Php 读取SOAP XML文件
我有一个SOAP XML文件(data.XML),其中包含以下数据,实际上它是一些API的响应:Php 读取SOAP XML文件,php,xml,arrays,soap,Php,Xml,Arrays,Soap,我有一个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.
<?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>
第二次尝试:
$s = simplexml_load_string('http://localhost/adam_auction/data.xml');
print_r($s);
错误:
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
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
警告:simplexml\u load\u string():实体:第1行:解析器错误:应为开始标记,您需要使用simplexml\u load\u文件
$s = simplexml_load_file('http://localhost/adam_auction/data.xml');
print_r($s);
您需要使用simplexml\u load\u文件
$s = simplexml_load_file('http://localhost/adam_auction/data.xml');
print_r($s);
写得不好,但解决了问题。只删除Soap信封的基本标记,加载XML并用“@”打印
$response = file_get_contents($file_path);
$response = explode(PHP_EOL, $response);
$skip = array(0, 1, 2, count($response)-1, count($response)-2);
$xml = array();
for($i=0;$i<count($response);$i++){
if(!in_array($i, $skip)){
$xml[] = $response[$i];
}
}
$xml = implode('', $xml);
@print_r(simplexml_load_string($xml));
// or
@$obj = simplexml_load_string($xml);
$response=file\u get\u contents($file\u path);
$response=explode(PHP\u EOL,$response);
$skip=array(0,1,2,count($response)-1,count($response)-2);
$xml=array();
对于($i=0;$i),虽然写得不好,但解决了问题。只删除Soap信封的基本标记,加载XML并用“@”打印
$response = file_get_contents($file_path);
$response = explode(PHP_EOL, $response);
$skip = array(0, 1, 2, count($response)-1, count($response)-2);
$xml = array();
for($i=0;$i<count($response);$i++){
if(!in_array($i, $skip)){
$xml[] = $response[$i];
}
}
$xml = implode('', $xml);
@print_r(simplexml_load_string($xml));
// or
@$obj = simplexml_load_string($xml);
$response=file\u get\u contents($file\u path);
$response=explode(PHP\u EOL,$response);
$skip=array(0,1,2,count($response)-1,count($response)-2);
$xml=array();
对于($i=0;$i最终,我得到了解决方案。我刚刚删除了'xmlns=“gdauctionsbidingwsapi'”名称空间,它就成功了
// getting response from API despite saving it to file
$response= str_replace('GdAuctionsBiddingWSAPI', '', $response);
$xml = simplexml_load_string($response);
$auction_list = $xml->xpath('//Auction');
foreach ($auction_list as $item) {
foreach($item->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
}
现在,我可以遍历每个属性了。谢谢你,我终于找到了解决方案。我刚刚删除了'xmlns=“GdAuctionsBiddingWSAPI”'名称空间,它就工作了
// getting response from API despite saving it to file
$response= str_replace('GdAuctionsBiddingWSAPI', '', $response);
$xml = simplexml_load_string($response);
$auction_list = $xml->xpath('//Auction');
foreach ($auction_list as $item) {
foreach($item->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
}
现在,我可以遍历每个属性了。谢谢你为什么不使用SoapClient
@DevZer0,我确实要求使用SoapClient,但无法通过SoapClient。你能帮助我如何提出SoapClient请求吗?你可以从上面的链接找到我的代码。你为什么不使用SoapClient
@DevZer0,我确实要求使用SoapClient but无法通过SoapClient完成。您可以帮助如何发出SoapClient请求吗?您可以从上面的链接找到我的代码。simplexml\u load\u文件和simplexml\u load\u字符串都会产生相同的错误。如何通过SoapClient进行帮助,下面是simplexml\u load\u文件和simplexml\u load\u字符串都会产生相同错误的代码。如何通过SoapClien进行帮助t、 这是代码