Parses XML response into array.

This is what reads the response XML and converts it into an array.
@param SimpleXMLElement $xml <p>The XML response from Amazon.</p>
@return boolean <b>FALSE</b> if no XML data is found
510414
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->children() as $key=>$x){
            $i = $this->index;
            if ($key != 'ReportInfo'){
                continue;
            }
            
            $this->reportList[$i]['ReportId'] = (string)$x->ReportId;
            $this->reportList[$i]['ReportType'] = (string)$x->ReportType;
            $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId;
            $this->reportList[$i]['AvailableDate'] = (string)$x->AvailableDate;
            $this->reportList[$i]['Acknowledged'] = (string)$x->Acknowledged;
            if (isset($x->AcknowledgedDate)) {
                $this->reportList[$i]['AcknowledgedDate'] = (string)$x->AcknowledgedDate;
            }
            
            $this->index++;
        }
    }
495143
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        
        foreach($xml->children() as $key=>$x){
            $i = $this->index;
            if ($key == 'Count'){
                $this->count = (string)$x;
                $this->log("Successfully canceled $this->count report requests.");
            }
            if ($key != 'ReportRequestInfo'){
                continue;
            }
            
            $this->reportList[$i]['ReportRequestId'] = (string)$x->ReportRequestId;
            $this->reportList[$i]['ReportType'] = (string)$x->ReportType;
            $this->reportList[$i]['StartDate'] = (string)$x->StartDate;
            $this->reportList[$i]['EndDate'] = (string)$x->EndDate;
            $this->reportList[$i]['Scheduled'] = (string)$x->Scheduled;
            $this->reportList[$i]['SubmittedDate'] = (string)$x->SubmittedDate;
            $this->reportList[$i]['ReportProcessingStatus'] = (string)$x->ReportProcessingStatus;
            $this->reportList[$i]['GeneratedReportId'] = (string)$x->GeneratedReportId;
            $this->reportList[$i]['StartedProcessingDate'] = (string)$x->StartedProcessingDate;
            $this->reportList[$i]['CompletedDate'] = (string)$x->CompletedDate;
            
            $this->index++;
        }
    }
1129568
public static function xml2arr($xml)
    {
        $entity = libxml_disable_entity_loader(true);
        $data = (array)simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
        libxml_disable_entity_loader($entity);
        return json_decode(json_encode($data), true);
    }
1349990
public static function parseExpressionXml(SimpleXMLElement $xml){
        $returnValue = self::parseElementXml($xml);
        $value = trim($xml);
        $expressions = array();
        foreach($xml->children() as $child){
            $expressions[] = self::parseExpressionXml($child);
        }
        if(count($expressions)){
            $returnValue['expressions'] = $expressions;
        }
        if(strlen($value)){
            $returnValue['value'] = $value;
        }
        return $returnValue;
    }
518558
public function toArray( $xml )
	{
		$this->data	= array();
		$this->xml	= xml_parser_create();
		xml_set_object( $this->xml, $this );
		xml_set_element_handler( $this->xml, 'handleTagOpenForArray', 'handleTagCloseForArray' );
		xml_set_character_data_handler( $this->xml, 'handleCDataForArray' );
		$this->last	= array( &$this->data );
		if( !xml_parse( $this->xml, $xml ) )
		{
			$msg	= "XML error: %s at line %d";
			$error	= xml_error_string( xml_get_error_code( $this->xml ) );
			$line	= xml_get_current_line_number( $this->xml );
			throw new RuntimeException( sprintf( $msg, $error, $line ) );
		}
		xml_parser_free( $this->xml );
		return $this->data;
	}
1030442
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->ShipmentData->children() as $x){
            $a = array();

            if (isset($x->ShipmentId)){
                $a['ShipmentId'] = (string)$x->ShipmentId;
            }
            if (isset($x->ShipmentName)){
                $a['ShipmentName'] = (string)$x->ShipmentName;
            }

            //Address
            $a['ShipFromAddress']['Name'] = (string)$x->ShipFromAddress->Name;
            $a['ShipFromAddress']['AddressLine1'] = (string)$x->ShipFromAddress->AddressLine1;
            if (isset($x->ShipFromAddress->AddressLine2)){
                $a['ShipFromAddress']['AddressLine2'] = (string)$x->ShipFromAddress->AddressLine2;
            } else {
                $a['ShipFromAddress']['AddressLine2'] = null;
            }
            $a['ShipFromAddress']['City'] = (string)$x->ShipFromAddress->City;
            if (isset($x->ShipFromAddress->DistrictOrCounty)){
                $a['ShipFromAddress']['DistrictOrCounty'] = (string)$x->ShipFromAddress->DistrictOrCounty;
            } else {
                $a['ShipFromAddress']['DistrictOrCounty'] = null;
            }
            $a['ShipFromAddress']['StateOrProvinceCode'] = (string)$x->ShipFromAddress->StateOrProvinceCode;
            $a['ShipFromAddress']['CountryCode'] = (string)$x->ShipFromAddress->CountryCode;
            $a['ShipFromAddress']['PostalCode'] = (string)$x->ShipFromAddress->PostalCode;

            if (isset($x->DestinationFulfillmentCenterId)){
                $a['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId;
            }
            if (isset($x->LabelPrepType)){
                $a['LabelPrepType'] = (string)$x->LabelPrepType;
            }
            if (isset($x->ShipmentStatus)){
                $a['ShipmentStatus'] = (string)$x->ShipmentStatus;
            }

            $a['AreCasesRequired'] = (string)$x->AreCasesRequired;

            if (isset($x->ConfirmedNeedByDate)){
                $a['ConfirmedNeedByDate'] = (string)$x->ConfirmedNeedByDate;
            }
            
            $this->shipmentList[$this->index] = $a;
            $this->index++;
        }
    }
354579
protected function simpleXmlToArray(SimpleXMLElement $xml) {
		$result = [];
		
		foreach ($xml as $element) {
			$name    = $element->getName();
			$content = get_object_vars($element);
			
			if (isset($content['@attributes'])){
				if (isset($content['@attributes']['value'])) {
					$result[$name] = Std::parseValue($content['@attributes']['value']);
					continue;
				}
				
				unset($content['@attributes']);
			}
			
			if (empty($content)) {
				$result[$name] = Std::parseValue($element);
				continue;
			}
			
			$result[$name] = $this->simpleXmlToArray($element);
		}
		
		return $result;
	}
820
public function xml2array(\SimpleXMLElement $xml)
    {
        $arr = array();
        foreach ($xml as $element) {
            $tag = $element->getName();
            $e = get_object_vars($element);
            if (!empty($e)) {
                $arr[$tag][] = $element instanceof \SimpleXMLElement ? $this->xml2array($element) : $e;
            } else {
                $arr[$tag] = trim($element);
            }
        }

        return $arr;
    }
202125
public function parseXML($xml)
    {
        $document = new \DOMDocument();

        $previousValue = libxml_use_internal_errors(true);
        libxml_clear_errors();
        $result = $document->loadXML($xml);
        /** @var \libXMLError[] $errors */
        $errors = libxml_get_errors();
        libxml_clear_errors();
        libxml_use_internal_errors($previousValue);

        if (true !== $result) {
            $message = [];
            foreach ($errors as $error) {
                $message[] = sprintf(
                    '%d. [%s] %s in on line %d in position %d',
                    count($message) + 1,
                    $error->code,
                    str_replace(["\n", "\r"], '', $error->message),
                    $error->line,
                    $error->column
                );
            }
            throw new RuntimeException('Can not parse XML: ' . implode('; ', $message));
        }

        return $this->parseDocument($document);
    }
1273253
public function fromXml(string $xml): array
    {
        if (!$this->isEmptyValue($xml)) {

            libxml_use_internal_errors(true);

            // convert string to xml object
            $result = simplexml_load_string("$xml", 'SimpleXMLElement', LIBXML_NOCDATA);

            if ($result) {
                return $this->fromClass($result);

            } else {

                foreach (libxml_get_errors() as $error) {

                    // if don`t have container add that`s
                    if ($error->code == 5) {
                        $this->errors = [];

                        // append container and parse again
                        return $this->fromXml("<DATA>$xml</DATA>");

                    } else
                        $this->setError($error->code, $error->message);
                }
            }
        }

        return $this->result;
    }
1138286
protected function parseXml($xml) {
        if (!$xml){
            return false;
        }

        //response from send, confirm, estimate, void
        if (isset($xml->TransportResult->TransportStatus)) {
            $this->status = (string)$xml->TransportResult->TransportStatus;
        }
        //response from get
        if (isset($xml->TransportContent)) {
            $this->contents = array();
            $this->status = (string)$xml->TransportContent->TransportResult->TransportStatus;
            $this->contents['SellerId'] = (string)$xml->TransportContent->TransportHeader->SellerId;
            $this->contents['ShipmentId'] = (string)$xml->TransportContent->TransportHeader->ShipmentId;
            $this->contents['IsPartnered'] = (string)$xml->TransportContent->TransportHeader->IsPartnered;
            $this->contents['ShipmentType'] = (string)$xml->TransportContent->TransportHeader->ShipmentType;

            //one of four possible response structures for details
            $this->contents['Details'] = array();
            $d = array();
            if (isset($xml->TransportContent->TransportDetails->PartneredSmallParcelData)) {
                //Partnered + SP
                $d = $xml->TransportContent->TransportDetails->PartneredSmallParcelData;
            } else if (isset($xml->TransportContent->TransportDetails->NonPartneredSmallParcelData)) {
                //Non-Partnered + SP
                $d = $xml->TransportContent->TransportDetails->NonPartneredSmallParcelData;
            } else if (isset($xml->TransportContent->TransportDetails->PartneredLtlData)) {
                //Partnered + LTL
                $d = $xml->TransportContent->TransportDetails->PartneredLtlData;
                $this->contents['Details']['Contact']['Name'] = (string)$d->Contact->Name;
                $this->contents['Details']['Contact']['Phone'] = (string)$d->Contact->Phone;
                $this->contents['Details']['Contact']['Email'] = (string)$d->Contact->Email;
                $this->contents['Details']['Contact']['Fax'] = (string)$d->Contact->Fax;
                $this->contents['Details']['BoxCount'] = (string)$d->BoxCount;
                if (isset($d->SellerFreightClass)) {
                    $this->contents['Details']['SellerFreightClass'] = (string)$d->SellerFreightClass;
                }
                $this->contents['Details']['FreightReadyDate'] = (string)$d->FreightReadyDate;
                foreach ($d->PalletList->children() as $x) {
                    $temp = array();
                    $temp['IsStacked'] = (string)$x->IsStacked;
                    $temp['Dimensions']['Unit'] = (string)$x->Dimensions->Unit;
                    $temp['Dimensions']['Length'] = (string)$x->Dimensions->Length;
                    $temp['Dimensions']['Width'] = (string)$x->Dimensions->Width;
                    $temp['Dimensions']['Height'] = (string)$x->Dimensions->Height;
                    if (isset($x->Weight)) {
                        $temp['Weight']['Value'] = (string)$x->Weight->Value;
                        $temp['Weight']['Unit'] = (string)$x->Weight->Unit;
                    }
                    $this->contents['Details']['PalletList'][] = $temp;
                }
                $this->contents['Details']['TotalWeight']['Value'] = (string)$d->TotalWeight->Value;
                $this->contents['Details']['TotalWeight']['Unit'] = (string)$d->TotalWeight->Unit;
                if (isset($d->SellerDeclaredValue)) {
                    $this->contents['Details']['SellerDeclaredValue']['Value'] = (string)$d->SellerDeclaredValue->Value;
                    $this->contents['Details']['SellerDeclaredValue']['CurrencyCode'] = (string)$d->SellerDeclaredValue->CurrencyCode;
                }
                if (isset($d->AmazonCalculatedValue)) {
                    $this->contents['Details']['AmazonCalculatedValue']['Value'] = (string)$d->AmazonCalculatedValue->Value;
                    $this->contents['Details']['AmazonCalculatedValue']['CurrencyCode'] = (string)$d->AmazonCalculatedValue->CurrencyCode;
                }
                $this->contents['Details']['PreviewPickupDate'] = (string)$d->PreviewPickupDate;
                $this->contents['Details']['PreviewDeliveryDate'] = (string)$d->PreviewDeliveryDate;
                $this->contents['Details']['PreviewFreightClass'] = (string)$d->PreviewFreightClass;
                $this->contents['Details']['AmazonReferenceId'] = (string)$d->AmazonReferenceId;
                $this->contents['Details']['IsBillOfLadingAvailable'] = (string)$d->IsBillOfLadingAvailable;
                $this->contents['Details']['CarrierName'] = (string)$d->CarrierName;
            } else if (isset($xml->TransportContent->TransportDetails->NonPartneredLtlData)) {
                //Non-Partnered + LTL
                $d = $xml->TransportContent->TransportDetails->NonPartneredLtlData;
                $this->contents['Details']['CarrierName'] = (string)$d->CarrierName;
                $this->contents['Details']['ProNumber'] = (string)$d->ProNumber;
            }
            //shared by both SP structures
            if (isset($d->PackageList)) {
                foreach ($d->PackageList->children() as $x) {
                    $temp = array();
                    $temp['TrackingId'] = (string)$x->TrackingId;
                    $temp['PackageStatus'] = (string)$x->PackageStatus;
                    $temp['CarrierName'] = (string)$x->CarrierName;
                    if (isset($x->Weight)) {
                        $temp['Weight']['Value'] = (string)$x->Weight->Value;
                        $temp['Weight']['Unit'] = (string)$x->Weight->Unit;
                    }
                    if (isset($x->Dimensions)) {
                        $temp['Dimensions']['Unit'] = (string)$x->Dimensions->Unit;
                        $temp['Dimensions']['Length'] = (string)$x->Dimensions->Length;
                        $temp['Dimensions']['Width'] = (string)$x->Dimensions->Width;
                        $temp['Dimensions']['Height'] = (string)$x->Dimensions->Height;
                    }
                    $this->contents['Details']['PackageList'][] = $temp;
                }
            }
            //shared by both partnered structures
            if (isset($d->PartneredEstimate)) {
                $pe = array();
                $pe['Amount']['Value'] = (string)$d->PartneredEstimate->Amount->Value;
                $pe['Amount']['CurrencyCode'] = (string)$d->PartneredEstimate->Amount->CurrencyCode;
                if (isset($d->PartneredEstimate->ConfirmDeadline)) {
                    $pe['ConfirmDeadline'] = (string)$d->PartneredEstimate->ConfirmDeadline;
                }
                if (isset($d->PartneredEstimate->ConfirmDeadline)) {
                    $pe['VoidDeadline'] = (string)$d->PartneredEstimate->VoidDeadline;
                }
                $this->contents['Details']['PartneredEstimate'] = $pe;
            }
        }
    }
1172932
public static function parse($xml)
    {
        $data = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOBLANKS);

        if (is_object($data) && get_class($data) === 'SimpleXMLElement') {
            $data = self::arrarval($data);
        }

        return $data;
    }
1276236
private function xmlToElements($xml)
    {
        //====================================================================//
        // Convert XML to Object Recursively
        try {
            $result = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOERROR);
        } catch (Exception $ex) {
            $this->fault = $ex->getMessage();

            return false;
        }

        return $result;
    }
882662
protected function parseXML($xml) {
        if (!$xml){
            return false;
        }
        $i = 0;
        foreach($xml->children() as $x){
            foreach($x->ShipToAddress->children() as $y => $z){
                $this->planList[$i]['ShipToAddress'][$y] = (string)$z;
                
            }
            $this->planList[$i]['ShipmentId'] = (string)$x->ShipmentId;
            $this->planList[$i]['DestinationFulfillmentCenterId'] = (string)$x->DestinationFulfillmentCenterId;
            $this->planList[$i]['LabelPrepType'] = (string)$x->LabelPrepType;
            $j = 0;
            foreach($x->Items->children() as $y => $z){
                $this->planList[$i]['Items'][$j]['SellerSKU'] = (string)$z->SellerSKU;
                $this->planList[$i]['Items'][$j]['Quantity'] = (string)$z->Quantity;
                $this->planList[$i]['Items'][$j]['FulfillmentNetworkSKU'] = (string)$z->FulfillmentNetworkSKU;
                if (isset($z->PrepDetailsList)) {
                    foreach ($z->PrepDetailsList as $zz) {
                        $temp = array();
                        $temp['PrepInstruction'] = (string)$zz->PrepInstruction;
                        $temp['PrepOwner'] = (string)$zz->PrepOwner;
                        $this->planList[$i]['Items'][$j]['PrepDetailsList'][] = $temp;
                    }
                }
                $j++;
                
            }
            $i++;
        }
    }
1164724
protected static function xmlToArray(\SimpleXMLElement $xml)/*# : array */
    {
        $arr = array();
        foreach ($xml as $element) {
            $tag = $element->getName();
            $ele = get_object_vars($element);
            if (!empty($ele)) {
                $arr[$tag] = $element instanceof \SimpleXMLElement ?
                    static::xmlToArray($element) :
                    $ele;
            } else {
                $arr[$tag] = trim($element);
            }
        }
        return $arr;
    }
1141594
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        
        foreach($xml->children() as $item){
            $n = $this->index;
            
            $this->itemList[$n]['ASIN'] = (string)$item->ASIN;
            $this->itemList[$n]['SellerSKU'] = (string)$item->SellerSKU;
            $this->itemList[$n]['OrderItemId'] = (string)$item->OrderItemId;
            $this->itemList[$n]['Title'] = (string)$item->Title;
            $this->itemList[$n]['QuantityOrdered'] = (string)$item->QuantityOrdered;
            if (isset($item->QuantityShipped)){
                $this->itemList[$n]['QuantityShipped'] = (string)$item->QuantityShipped;
            }
            if (isset($item->BuyerCustomizedInfo->CustomizedURL)){
                $this->itemList[$n]['BuyerCustomizedInfo'] = (string)$item->BuyerCustomizedInfo->CustomizedURL;
            }
            if (isset($item->PointsGranted)){
                $this->itemList[$n]['PointsGranted']['PointsNumber'] = (string)$item->PointsGranted->PointsNumber;
                $this->itemList[$n]['PointsGranted']['Amount'] = (string)$item->PointsGranted->PointsMonetaryValue->Amount;
                $this->itemList[$n]['PointsGranted']['CurrencyCode'] = (string)$item->PointsGranted->PointsMonetaryValue->CurrencyCode;
            }
            if (isset($item->PriceDesignation)){
                $this->itemList[$n]['PriceDesignation'] = (string)$item->PriceDesignation;
            }
            if (isset($item->GiftMessageText)){
                $this->itemList[$n]['GiftMessageText'] = (string)$item->GiftMessageText;
            }
            if (isset($item->GiftWrapLevel)){
                $this->itemList[$n]['GiftWrapLevel'] = (string)$item->GiftWrapLevel;
            }
            if (isset($item->ItemPrice)){
                $this->itemList[$n]['ItemPrice']['Amount'] = (string)$item->ItemPrice->Amount;
                $this->itemList[$n]['ItemPrice']['CurrencyCode'] = (string)$item->ItemPrice->CurrencyCode;
            }
            if (isset($item->ShippingPrice)){
                $this->itemList[$n]['ShippingPrice']['Amount'] = (string)$item->ShippingPrice->Amount;
                $this->itemList[$n]['ShippingPrice']['CurrencyCode'] = (string)$item->ShippingPrice->CurrencyCode;
            }
            if (isset($item->GiftWrapPrice)){
                $this->itemList[$n]['GiftWrapPrice']['Amount'] = (string)$item->GiftWrapPrice->Amount;
                $this->itemList[$n]['GiftWrapPrice']['CurrencyCode'] = (string)$item->GiftWrapPrice->CurrencyCode;
            }
            if (isset($item->ItemTax)){
                $this->itemList[$n]['ItemTax']['Amount'] = (string)$item->ItemTax->Amount;
                $this->itemList[$n]['ItemTax']['CurrencyCode'] = (string)$item->ItemTax->CurrencyCode;
            }
            if (isset($item->ShippingTax)){
                $this->itemList[$n]['ShippingTax']['Amount'] = (string)$item->ShippingTax->Amount;
                $this->itemList[$n]['ShippingTax']['CurrencyCode'] = (string)$item->ShippingTax->CurrencyCode;
            }
            if (isset($item->GiftWrapTax)){
                $this->itemList[$n]['GiftWrapTax']['Amount'] = (string)$item->GiftWrapTax->Amount;
                $this->itemList[$n]['GiftWrapTax']['CurrencyCode'] = (string)$item->GiftWrapTax->CurrencyCode;
            }
            if (isset($item->ShippingDiscount)){
                $this->itemList[$n]['ShippingDiscount']['Amount'] = (string)$item->ShippingDiscount->Amount;
                $this->itemList[$n]['ShippingDiscount']['CurrencyCode'] = (string)$item->ShippingDiscount->CurrencyCode;
            }
            if (isset($item->PromotionDiscount)){
                $this->itemList[$n]['PromotionDiscount']['Amount'] = (string)$item->PromotionDiscount->Amount;
                $this->itemList[$n]['PromotionDiscount']['CurrencyCode'] = (string)$item->PromotionDiscount->CurrencyCode;
            }
            if (isset($item->CODFee)){
                $this->itemList[$n]['CODFee']['Amount'] = (string)$item->CODFee->Amount;
                $this->itemList[$n]['CODFee']['CurrencyCode'] = (string)$item->CODFee->CurrencyCode;
            }
            if (isset($item->CODFeeDiscount)){
                $this->itemList[$n]['CODFeeDiscount']['Amount'] = (string)$item->CODFeeDiscount->Amount;
                $this->itemList[$n]['CODFeeDiscount']['CurrencyCode'] = (string)$item->CODFeeDiscount->CurrencyCode;
            }
            if (isset($item->PromotionIds)){
                $i = 0;
                foreach($item->PromotionIds->children() as $x){
                    $this->itemList[$n]['PromotionIds'][$i] = (string)$x;
                    $i++;
                }
            }
            if (isset($item->InvoiceData)){
                if (isset($item->InvoiceData->InvoiceRequirement)){
                    $this->itemList[$n]['InvoiceData']['InvoiceRequirement'] = (string)$item->InvoiceData->InvoiceRequirement;
                }
                if (isset($item->InvoiceData->BuyerSelectedInvoiceCategory)){
                    $this->itemList[$n]['InvoiceData']['BuyerSelectedInvoiceCategory'] = (string)$item->InvoiceData->BuyerSelectedInvoiceCategory;
                }
                if (isset($item->InvoiceData->InvoiceTitle)){
                    $this->itemList[$n]['InvoiceData']['InvoiceTitle'] = (string)$item->InvoiceData->InvoiceTitle;
                }
                if (isset($item->InvoiceData->InvoiceInformation)){
                    $this->itemList[$n]['InvoiceData']['InvoiceInformation'] = (string)$item->InvoiceData->InvoiceInformation;
                }
            }
            if (isset($item->ConditionId)){
                $this->itemList[$n]['ConditionId'] = (string)$item->ConditionId;
            }
            if (isset($item->ConditionSubtypeId)){
                $this->itemList[$n]['ConditionSubtypeId'] = (string)$item->ConditionSubtypeId;
            }
            if (isset($item->ConditionNote)){
                $this->itemList[$n]['ConditionNote'] = (string)$item->ConditionNote;
            }
            if (isset($item->ScheduledDeliveryStartDate)){
                $this->itemList[$n]['ScheduledDeliveryStartDate'] = (string)$item->ScheduledDeliveryStartDate;
            }
            if (isset($item->ScheduledDeliveryEndDate)){
                $this->itemList[$n]['ScheduledDeliveryEndDate'] = (string)$item->ScheduledDeliveryEndDate;
            }
            $this->index++;
        }
            
    }
1213329
private function parseXML($xml) {
		$simpleXml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
		$json = json_encode($simpleXml);

		return json_decode($json, true);
	}