转换XML到数组
@param \SimpleXMLElement|string $xml
@return array
963735
protected function convertXmlToArray($xml)
    {
        libxml_disable_entity_loader(true);
        return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    }
381480
public function xml2array($xml)
    {
        $xml = trim($xml);
        if (!$xml) {
            throw new EasyXMLException('You should provide a XML document.');
        }

        try {
            $xml = is_file($xml) ? file_get_contents($xml) : $xml;
            $dom = new DomDocument();
            $dom->loadXML($xml);
            return XML2Array::createArray($dom);
        } catch (\Exception $e) {
            throw new EasyXMLException('Invalid XML document given.');
        }
    }
41424
protected function loadXML($xml)
	{
		$this->checkUnsupported($xml);

		// Activate small nodes allocation and relax LibXML's hardcoded limits if applicable. Limits
		// on tags can be set during configuration
		$flags = (LIBXML_VERSION >= 20700) ? LIBXML_COMPACT | LIBXML_PARSEHUGE : 0;

		$useErrors = libxml_use_internal_errors(true);
		$dom       = new DOMDocument;
		$success   = $dom->loadXML($xml, $flags);
		libxml_use_internal_errors($useErrors);

		if (!$success)
		{
			throw new InvalidArgumentException('Cannot load XML: ' . libxml_get_last_error()->message);
		}

		return $dom;
	}
176362
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->children() as $x){
            $this->supplyList[$this->index]['SellerSKU'] = (string)$x->SellerSKU;
            $this->supplyList[$this->index]['ASIN'] = (string)$x->ASIN;
            $this->supplyList[$this->index]['TotalSupplyQuantity'] = (string)$x->TotalSupplyQuantity;
            $this->supplyList[$this->index]['FNSKU'] = (string)$x->FNSKU;
            $this->supplyList[$this->index]['Condition'] = (string)$x->Condition;
            $this->supplyList[$this->index]['InStockSupplyQuantity'] = (string)$x->InStockSupplyQuantity;
            if ((int)$x->TotalSupplyQuantity > 0){
                if ($x->EarliestAvailability->TimepointType == 'DateTime'){
                    $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->DateTime;
                } else {
                    $this->supplyList[$this->index]['EarliestAvailability'] = (string)$x->EarliestAvailability->TimepointType;
                }
            }
            if (isset($this->options['ResponseGroup']) && $this->options['ResponseGroup'] == 'Detailed' && isset($x->SupplyDetail)){
                $j = 0;
                foreach($x->SupplyDetail->children() as $z){
                    if ((string)$z->EarliestAvailableToPick->TimepointType == 'DateTime'){
                        $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->DateTime;
                    } else {
                        $this->supplyList[$this->index]['SupplyDetail'][$j]['EarliestAvailableToPick'] = (string)$z->EarliestAvailableToPick->TimepointType;
                    }
                    if ((string)$z->LatestAvailableToPick->TimepointType == 'DateTime'){
                        $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->DateTime;
                    } else {
                        $this->supplyList[$this->index]['SupplyDetail'][$j]['LatestAvailableToPick'] = (string)$z->LatestAvailableToPick->TimepointType;
                    }
                    $this->supplyList[$this->index]['SupplyDetail'][$j]['Quantity'] = (string)$z->Quantity;
                    $this->supplyList[$this->index]['SupplyDetail'][$j]['SupplyType'] = (string)$z->SupplyType;
                    $j++;
                }
            }
            $this->index++;
        }
    }
610194
public static function fromXml($xml): array
    {
        if (!$xml) {
            throw new InvalidArgumentException('Convert To Array Error! Invalid Xml!');
        }

        libxml_disable_entity_loader(true);

        return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA), JSON_UNESCAPED_UNICODE), true);
    }
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;
            }
        }
    }
338106
public function FromXML($xml)
	{
		$sxo = new SimpleXMLElement($xml);
		
		if($sxo->encoding == "base64")
		{
			$this->Data = base64_decode($sxo->data);
		}
		else
		{
			$this->Data = $sxo->data;
		}
		
		$this->Name = $attachment->name;
		$this->Type = $attachment->type;
		$this->Size = $attachment->size;
		$this->Extension = $attachment->extension;
	}
453792
protected static function xmlToArray(\SimpleXMLElement $element) : array
    {
        $data = (array)$element;
        foreach ($data as $key => $value) {
            if ($value instanceof \SimpleXMLElement) {
                $data[$key] = static::xmlToArray($value);
            }
        }

        return $data;
    }
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;
	}
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;
	}
305266
public static function parse( $xml )
	{
		$channelData	= array();
		$itemList		= array();
		$xml	= new SimpleXMLElement( $xml );
		foreach( $xml->channel->children() as $nodeName => $nodeValue )
		{
			if( $nodeName == "image" && $nodeValue->children() )
			{
				$channelData[$nodeName]	= self::readSubSet( $nodeValue );
				continue;
			}
			if( $nodeName == "textInput" && $nodeValue->children() )
			{
				$channelData[$nodeName]	= self::readSubSet( $nodeValue );
				continue;
			}
			if( $nodeName != "item" )
			{
				$channelData[$nodeName]	= (string) $nodeValue;
				continue;
			}
			$item		= array();
			$itemNode	= $nodeValue;
			foreach( $itemNode->children() as $nodeName => $nodeValue )
				$item[$nodeName]	= (string) $nodeValue;
			$itemList[]	= $item;
		}
		$attributes	= $xml->attributes();
		$data	= array(
			'encoding'		=> $attributes['encoding'],
			'channelData'	=> $channelData,
			'itemList'		=> $itemList,
		);
		return $data;
	}
1097116
static public function xmlToArray($xml)
    {
        //禁止引用外部xml实体
        libxml_disable_entity_loader(true);
        $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
        return $values;
    }
362578
private static function getXml(\SimpleXMLElement $element) {
        $getTest = $element->asXML();
        if ($getTest === false) {
            $getTest = '';
        }

        return $getTest;
    }
370658
protected function parseXml($xml)
    {
        $data = array();
        
        foreach ($xml->children() as $name => $child) {
            if (count($child->children()) > 0) {
                $value = $this->parseXml($child);
            } else {
                $value = (string) $child;
            }

            $node = array(
                'tag'   => $name,
                'value' => $value
            );

            foreach ($child->attributes() as $name => $value) {
                $node['attributes'][$name] = (string) $value[0];
            }
            
            $data[] = $node;
        }

        return $data;
    }
756815
protected function getEnzymes(\SimpleXMLElement $xml)
    {
        $enzymes = array();

        foreach ($xml->Enzyme as $xmlEnzyme) {
            $enzyme = $this->getEnzyme($xmlEnzyme);

            if (isset($enzyme['id'])) {
                $enzymes[$enzyme['id']] = $enzyme;
                continue;
            }

            $enzymes[] = $enzyme;
        }

        return $enzymes;
    }
854812
public static function toSimpleXMLElement($xml)
    {
        if ($xml instanceof \SimpleXMLElement) {
            return $xml;
        }

        if ($xml instanceof \DOMDocument) {
            return simplexml_import_dom($xml);
        }

        if (is_string($xml)) {

            if (is_file($xml)) {
                return simplexml_load_file($xml);
            }

            return simplexml_load_string($xml);
        }

        $type = is_object($xml) ? get_class($xml) : gettype($xml);

        throw new \InvalidArgumentException("Cannot convert instance of '$type' to DOMDocument");
    }
987269
protected function parseFee($xml) {
        $r = array();
        $r['FeeType'] = (string)$xml->FeeType;
        $r['Amount'] = (string)$xml->FeeAmount->CurrencyAmount;
        $r['CurrencyCode'] = (string)$xml->FeeAmount->CurrencyCode;
        return $r;
    }