CData字符串未完成?

时间:2012-05-17 05:53:20

标签: php xml-parsing simplexml

我有一个脚本来解析产品的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&#44; 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&#44; 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块似乎是一个正确形成的块。 (由于它的成人性质,我不能在这里发布。)

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

CDATA并不意味着你可以放入任何东西,它意味着事情可能会与标记符号混淆,而解析器可以忽略它。因此,CDATA中的字符必须包含除TAB,CR,LF或特殊FFFE,FFFF字符以外的一些控制字符。删除它们,你将有一个美好的一天!

答案 1 :(得分:0)

您应该尝试在工作站本地将该文档保存为xml文件,并在Internet Explorer或Firefox浏览器中打开(或者可以解析和验证XML文档的内容)以及您需要修复的任何错误。

对我而言,看起来它是一些非标准字符,它通过介于两者之间来保持你的CDATA部分不完整。

相关问题