【发布时间】:2013-08-13 17:03:20
【问题描述】:
我正在尝试将 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 数组?
【问题讨论】:
-
您是否考虑过使用 SoapClient 与 API 进行交互?它将以数组/对象的形式返回响应。php.net/soapclient
-
此外,使用 simplexml_load_string 加载的相同字符串在这里也可以正常工作。错误似乎出现在文本的另一部分。
-
@Hisamu,我还没有考虑 SoapClient,我正在使用 CURL。如果您解析该字符串,它会返回有效的数组,但实际上响应是 SOAP XML 响应,并且不容易解析。
-
你能把整个回复贴在一个粘贴箱里,这样我就可以在这里测试了吗?
-
@Hisamu,这是我的全部回复:pastebin.com/9wzUV8Pw。请帮助如何将其转换为数组。