我有包含以下数据的 SOAP XML 文件(data.xml),实际上它是一些 API 的响应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetAuctionList2Response xmlns="GdAuctionsBiddingWSAPI">
<GetAuctionList2Result>
<AuctionList IsValid="True" TotalRecords="98">
<Auction ID="112910726" Name="SOFTWARE-SERVER.ORG" Traffic="2" BidCount="0" Price="$9 USD" ValuationPrice="-" TimeLeft="9H 36M " RowID="1"/>
<Auction ID="112926015" Name="SOFTWARELAWSUITS.COM" Traffic="0" BidCount="0" Price="$8 USD" ValuationPrice="-" TimeLeft="9H 39M " RowID="2"/>
<Auction ID="113234131" Name="SOFTWARECRAFTORY.COM" Traffic="4" BidCount="0" Price="$11 USD" ValuationPrice="-" TimeLeft="9H 53M " RowID="3"/>
<Auction ID="112906125" Name="SOFTWARESYSTEMS.CO" Traffic="0" BidCount="0" Price="$8 USD" ValuationPrice="-" TimeLeft="10H 15M " RowID="4"/>
<Auction ID="112692380" Name="SOFTWAREREPAIR.ORG" Traffic="0" BidCount="0" Price="$5 USD" ValuationPrice="-" TimeLeft="10H 46M " RowID="5"/>
</AuctionList>
</GetAuctionList2Result>
</GetAuctionList2Response>
</soap:Body>
</soap:Envelope>
当我尝试阅读它时,它不起作用并引发错误。第一次尝试:
$doc = new DOMDocument();
$doc->load( 'data.xml' );
$auctionList = $doc->getElementsByTagName( "AuctionList" );
foreach( $auctionList as $list ) {
$names = $list->getElementsByTagName( "Auction" );
echo "<b>$name\n</b><br>";
}
错误:
Notice: DOMDocument::load(): xmlns: URI GdAuctionsBiddingWSAPI is not absolute in file:///C:/xampp/htdocs/adam_auction/data.xml, line: 4 in C:\xampp\htdocs\adam_auction\readfile.php on line 5
Notice: Undefined variable: name in C:\xampp\htdocs\adam_auction\readfile.php on line 13
第二次尝试:
$s = simplexml_load_string('http://localhost/adam_auction/data.xml');
print_r($s);
错误:
Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in C:\xampp\htdocs\adam_auction\readfile.php on line 4
Warning: simplexml_load_string(): http://localhost/adam_auction/data.xml in C:\xampp\htdocs\adam_auction\readfile.php on line 4
Warning: simplexml_load_string(): ^ in C:\xampp\htdocs\adam_auction\readfile.php on line 4
谁能帮助我 SOAP XML 文件有什么问题?
1) XML 文件是否无效?2)如何读取它并将其保存到某个变量?3) 如何获取“拍卖”标签信息并将其保存到数组中?