1

我正在尝试将 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 数组?

4

1 回答 1

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
        )

)
于 2013-08-14T12:21:10.423 回答