转换为PHP对象的XML API响应中的访问数组
有人知道如何访问SOAP API返回的SimpleXMLElement对象中的转换为PHP对象的XML API响应中的访问数组,php,xml,soap,Php,Xml,Soap,有人知道如何访问SOAP API返回的SimpleXMLElement对象中的[@attributes]数组吗 我无法检索[@attributes]数组的TotalAmount元素的值。@就是我被卡住的地方 下面是返回完整响应的代码的结尾: $response = curl_exec($ch); $xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOWARNING); $xml_response = $xml-&
[@attributes]
数组吗
我无法检索[@attributes]
数组的TotalAmount
元素的值。@
就是我被卡住的地方
下面是返回完整响应的代码的结尾:
$response = curl_exec($ch);
$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOWARNING);
$xml_response = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children();
echo '<pre>';
print_r($xml_response);
echo '</pre>';
这将检索我想要的数据部分,但我不知道如何访问[@attributes]
数组
SimpleXMLElement Object
(
[CalculatePostageRateResponse] => SimpleXMLElement Object
(
[PostageRateResponse] => SimpleXMLElement Object
(
[Status] => 0
[Zone] => 5
[PostagePrice] => SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 8.15
)
[MailClass] => Priority
[Postage] => SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 8.15
)
[MailService] => Priority Mail
[Zone] => 5
[IntraBMC] => false
[Pricing] => CommercialBase
)
[Fees] => SimpleXMLElement Object
(
[@attributes] => Array
(
[TotalAmount] => 0
)
[CertificateOfMailing] => 0
[CertifiedMail] => 0
[CollectOnDelivery] => 0
[DeliveryConfirmation] => 0
[ElectronicReturnReceipt] => 0
[InsuredMail] => 0
[RegisteredMail] => 0
[RestrictedDelivery] => 0
[ReturnReceipt] => 0
[ReturnReceiptForMerchandise] => 0
[SignatureConfirmation] => 0
[SpecialHandling] => 0
[MerchandiseReturn] => 0
[OpenAndDistribute] => 0
[AdultSignature] => 0
[AdultSignatureRestrictedDelivery] => 0
[LiveAnimalSurcharge] => 0
[FragileHandling] => 0
[AMDelivery] => 0
[GroupedExtraServices] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Services] =>
)
[FeeAmount] => 0
)
)
[DeliveryTimeDays] => 2
[EstimatedDeliveryDate] => 6/1/2018
[DdpRate] => 0
)
)
)
)
我将非常感谢任何帮助
下面是整个$xml\u响应:
$response = curl_exec($ch);
$xml = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOWARNING);
$xml_response = $xml->children('http://schemas.xmlsoap.org/soap/envelope/')->Body->children();
echo '<pre>';
print_r($xml_response);
echo '</pre>';
$postage = $xml_response->CalculatePostageRateResponse->PostageRateResponse->PostagePrice->Postage[0]['TotalAmount'];
解决方案
$postage = $xml_response->CalculatePostageRateResponse->PostageRateResponse->PostagePrice->Postage[0]['TotalAmount'];