我已經創建了一個腳本,它從URL獲取XML並更新mysql數據庫並將數據解析爲csv文件。SimpleXML XML解析
我得到XML中的HTML字符串,他們不應該在那裏。如何在解析時刪除它們?
我加載像這樣的XML文件:
$xml = simplexml_load_file(utf8_encode($xml_url), 'SimpleXMLElement', LIBXML_NOCDATA);
錯誤運行腳本時,我得到:
Warning: simplexml_load_file() [function.simplexml-load-file]: http://domain.com/api/get_catalog.php?id=351&user=878&key=b8:1: parser error : Space required after the Public Identifier in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]:^in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]: http://domain.com/api/get_catalog.php?id=351&user=878&key=b8:1: parser error : SystemLiteral " or ' expected in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]:^in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]: http://domain.com/api/get_catalog.php?id=351&user=878&key=b8:1: parser error : SYSTEM or PUBLIC, the URI is missing in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
Warning: simplexml_load_file() [function.simplexml-load-file]:^in /dokumenti/skripte/xmlupdate/lost/test/lost_xml.php on line 59
xml $ not loaded.
當我使用Firefox和從URL保存XML到磁盤我沒有問題解析它只是當我試圖從URL中獲取它。
XML看起來不錯:XML的 部分:
<?xml version="1.0" encoding="UTF-8"?>
<RecroKatalog>
<viewCustomerDiscount>
<BrojArtikla>10214</BrojArtikla>
<Naziv>Eksterno kucište 2.5" S-ATA+IDE HDD, Aluminium, USB 2.0</Naziv>
<NetoPrice>81.8224</NetoPrice>
<Status>Dostupno</Status>
<Opis></Opis>
<dugi_opis>Isporucuje se u SIVOJ boji</dugi_opis>
<Image>http://shop.lost.hr/data/images/big/10.jpg</Image>
<WEB_Grupa>Ladice i eksterna kucišta - OSTALO</WEB_Grupa>
<Akcija>0</Akcija>
<Proizvodjac></Proizvodjac>
<Klasifikacija>PH-25SD-B/VK220</Klasifikacija>
</viewCustomerDiscount>
因爲它不是有效的xml。 –
看起來像附加行附加到您的XML當您遠程調用它,並導致它無效 – Wilq
首先,您可以使用XMLReader :: isValid(void)來查看您的xml文檔是否有效。 – user1929959