【问题标题】:how to read this xml, get "parser error : CData section not finished"如何阅读此 xml,得到“解析器错误:CData 部分未完成”
【发布时间】:2017-10-30 05:41:51
【问题描述】:

我正在尝试阅读此 xml: xml rss file

但没有成功..有这个错误

    Warning: simplexml_load_file(): http://noticias.perfil.com/feed/:232: parser error : CData section not finished <p>La sola lectura de los datos estadísticos desp in D:\xampp\FerreWoo\scrap-rvnot.php on line 43

    Warning: simplexml_load_file(): Isis, con lo que habría logrado un nuevo respaldo a sus proyectos terroristas. in D:\xampp\FerreWoo\scrap-rvnot.php on line 43

    Warning: simplexml_load_file(): ^ in D:\xampp\FerreWoo\scrap-rvnot.php on line 43

我正在使用此代码:

   $feed = simplexml_load_file($urls, null, LIBXML_NOCDATA);

我也尝试使用 cURL,但仍然出现同样的错误。

我知道de xml文件可能不正确……但一定有办法读取它,对吧?

【问题讨论】:

  • 很可能密切相关:stackoverflow.com/questions/2798108/…。当我检索文件时,a sus proyectos terroristas. 后面有一个退格字符
  • 是的,我看到了...仍然无法使用您提供的链接修复它。

标签: php xml simplexml cdata


【解决方案1】:

该 XML 中有一些无效字符。试试下面的代码

$url    = 'http://noticias.perfil.com/feed/';
$html   = file_get_contents($url);
$invalid_characters = '/[^\x9\xa\x20-\xD7FF\xE000-\xFFFD]/';
$html = preg_replace($invalid_characters, '', $html);

$xml = simplexml_load_string($html);

//test purpose part 
$encode = json_encode($xml);
$decode = json_decode($encode, true);
print_r($decode);

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2011-02-17
    • 1970-01-01
    • 2021-12-15
    相关资源
    最近更新 更多