我有一个脚本可以解析产品的XML文件,但是我似乎无法掌握解析它的诀窍。我有代码:
$file = $shop_path.'datafeeds/MC-B01.xml';
$xml = simplexml_load_file($file, null, LIBXML_NOCDATA);
$items = $xml->Items;
for($i = 0; $i < 17000; $i++) {
$name = $items[$i]->Product_Name;
echo $name.'<br />';
}然而,我得到了各种奇怪的错误抛出:
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ./../datafeeds/MC-B01.xml:172439: parser error : CData section not finished
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ons, in or out of the water. Cleanup is a snap after the fun with Pipedream
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ^
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ./../datafeeds/MC-B01.xml:172439: parser error : PCDATA invalid Char value 3
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ons, in or out of the water. Cleanup is a snap after the fun with Pipedream
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ^
PHP Warning: in file C:/xampp/htdocs/trow/tools/rip.php on line 188: simplexml_load_file() [function.simplexml-load-file]: ./../datafeeds/MC-B01.xml:172439: parser error : Sequence ']]>' not allowed in content奇怪的是,包含错误显示的文本的CData块似乎是一个格式正确的块。(我不能在这里张贴,因为这是成人的天性。)
有什么建议吗?
发布于 2012-10-15 16:37:02
CDATA并不意味着你可以放入任何东西,它意味着一些东西可能与可以被解析器忽略的标记符号相混淆。因此,CDATA中的字符必须包含除TAB、CR、LF或特殊的FFFE、FFFF字符之外的一些控制字符。去掉它们,你就会有一个光明的一天!
发布于 2012-05-17 14:18:15
您应该尝试将该文档作为xml文件保存在本地工作站上,并在Internet Explorer或Firefox浏览器(或可以解析和验证XML文档的浏览器)中打开该文档,以及您需要修复的任何错误。
对我来说,它看起来像是一些非标准字符,它通过介于两者之间的方式保持CDATA部分的不完整。
https://stackoverflow.com/questions/10630548
复制相似问题