1

我创建了一个从 URL 获取 XML 并更新 mysql 数据库并将数据解析为 csv 文件的脚本。

我在 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 并将 XML 从 url 保存到磁盘时,当我尝试从 url 获取它时解析它没有问题。

XML 看起来不错: XML 的一部分:

<?xml version="1.0" encoding="UTF-8"?>
<RecroKatalog>
<viewCustomerDiscount>
    <BrojArtikla>10214</BrojArtikla>
    <Naziv>Eksterno kucište 2.5&quot; 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>
4

1 回答 1

6

错误消息中有一些巨大的线索。它抱怨看到:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

它是该网站提供的 HTML 文档的开始……而不是您要查找的 XML。

这通常发生在您必须针对远程服务进行身份验证时(因此在您登录时在浏览器中工作),但您并没有告诉 SimpleXML 为您执行此操作。

于 2013-01-22T19:03:09.980 回答