我正在尝试将XML SOAP响应转换为PHP数组,这里是XML SOAP响应:
string(1182) "<AuctionList IsValid="True" TotalRecords="90">
<Auction ID="112906125" Name="SOFTWARESYSTEMS.CO" Traffic="0" BidCount="0" Price="$11 USD" ValuationPrice="-" TimeLeft="17M 9S" RowID="1"/>
<Auction ID="112557715" Name="SOFTWAREINTEC.INFO" Traffic="0" BidCount="0" Price="$8 USD" ValuationPrice="-" TimeLeft="18M 9S" RowID="2"/>
<Auction ID="101835614" Name="SOFTWARERULETA.COM" Traffic="20" BidCount="0" Price="$25 USD" ValuationPrice="-" TimeLeft="24M 9S" RowID="3"/>
<Auction ID="112573759" Name="SOFTWAREINTEC.COM" Traffic="2" BidCount="0" Price="$5 USD" ValuationPrice="-" TimeLeft="28M 9S" RowID="4"/>
<Auction ID="112648957" Name="SOFTWAREASSETMANAGEMENTJOBS.COM" Traffic="7" BidCount="0" Price="$8 USD" ValuationPrice="-" TimeLeft="41M 9S" RowID="5"/>
</AuctionList>"
此回复是Godaddy拍卖API获取域名详情的结果。
我已经尝试过将其解析为字符串但却出错:
Warning: simplexml_load_string(): namespace warning : xmlns: URI GdAuctionsBiddingWSAPI is not absolute in C:\xampp\htdocs\adam_auction\index.php on line 94
Warning: simplexml_load_string(): w.w3.org/2001/XMLSchema"><GetAuctionList2Response xmlns="GdAuctionsBiddingWSAPI" in C:\xampp\htdocs\adam_auction\index.php on line 94
Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\adam_auction\index.php on line 94
object(SimpleXMLElement)#1 (1) { ["GetAuctionList2Response"]=> object(SimpleXMLElement)#2 (1) { ["GetAuctionList2Result"]=> string(768) "" } }
如何将该响应转换为PHP数组?
答案 0 :(得分:0)
试试这个
<?php
$xml = simplexml_load_string(your xml response);
$Auction = $xml->Auction;
foreach($Auction as $Auc)
{
$short_name[] = $Auc['Name'];
}
echo "<pre>";
print_r($short_name);
?>
输出
Array
(
[0] => SimpleXMLElement Object
(
[0] => SOFTWARESYSTEMS.CO
)
[1] => SimpleXMLElement Object
(
[0] => SOFTWAREINTEC.INFO
)
[2] => SimpleXMLElement Object
(
[0] => SOFTWARERULETA.COM
)
[3] => SimpleXMLElement Object
(
[0] => SOFTWAREINTEC.COM
)
[4] => SimpleXMLElement Object
(
[0] => SOFTWAREASSETMANAGEMENTJOBS.COM
)
)