我已经XML文档从链路捕获并随时我用使用simplexml_load_file(),它给了我*警告一个错误,说使用simplexml_load_file()开始标签预计, '<' 用C未找到:\ WAMP \ WWW \客商\ get_merchants.php第6行*使用simplexml_load_file()给错误:警告:使用simplexml_load_file():<a href="https://kga-dev.mirakl.net/api/shops?:1" rel="nofollow">https://kga-dev.mirakl.net/api/shops?:1</a>:分析器错误:
这是我的xml文件
<body>
<shops>
<shop>...</shop>
<shop>
<approval_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<approval_rate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<order_messages_response_delay xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<banner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<billing_info>
<bank_city xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bank_street xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<zip_code xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<bic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<iban xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<owner xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</billing_info>
的一部分,这是我的简单php代码
<?php
$apiLink = "https://kga-dev.mirakl.net/api/shops?";
$xml=simplexml_load_file($apiLink);
print_r($xml);
//echo $xml->shop_id;
?>
什么是读取XML数据的第一个标志?您是否试图通过file_get_contents()获取xml数据的第一个符号,然后找到可用的第一个符号。 SimpleXML需要一个“<”,这是没有给出的。因此,另一个标志是内容读入的第一个标志。它是哪一个?也许它有助于获得内容并修剪它? – Marcel
刚做了file_get_contents(),我得到了这个 {“shops”:[{“approval_delay”:null,“approval_rate”:null,“banner”:null,“billing_info”:{“bank_city”:null, :NULL, “bank_street”:NULL, “BIC”:NULL, “IBAN”:空, “所有者”:NULL, “ZIP_CODE”:空}, “信道”:[ “INIT”], “closed_from”:空, “closed_to”:null,“contact_informations”: – user3416016
正如你所看到的,这不是XML。这看起来像JSON中的REST Response。在这个内容上试试json_decode(),你就可以为你的问题找到解决方案。 – Marcel