开发者

XMLReader reports "Extra content at the end of the document" on an almost empty xml file

开发者 https://www.devze.com 2023-03-12 03:45 出处:网络
I\'ve problems using XMLReader on our live server while everything runs smoothly on our development servers. XMLReader always throws a \"parser error : Extra content at the end of the document\" while

I've problems using XMLReader on our live server while everything runs smoothly on our development servers. XMLReader always throws a "parser error : Extra content at the end of the document" while reading a xml file. Reg开发者_开发知识库ardless if it contains thousands of elements or just one line.

$reader = new \XMLReader();
$reader->open($xmlFileName, 'UTF-8');
while ( $reader->read() ) { ... do nothing ... }
$reader->close();

The xml looks like this in its most simple form:

<?xml version="1.0" encoding="UTF-8"?>
<data><articles><![CDATA[test]]></articles></data>

Every xml validator says it's well-formed but the errors are still thrown.

The only difference I can spot between our development and our live system is that our development system (Ubuntu) has the libxml2 version 2.7.16 while the live system (CentOs) has 2.6.16. Could this be the cause?


Different versions could always be a problem, although it may not answer what the problem is, only what solution you might need.

I'm suspicious of your CDATA handling (try spaces around the content, so ) and seem to remember some old bugs in regards to CDATA handling in your rather old production version, and also if you truly got UTF-8 happening (some libraries are sensitive to characters and default settings, like manual overrides ignored if the right setting is set. Also, is the '-' in 'UTF-8' an em-dash, normal dash or some other dash?)

Also, try to post your real XML, even in hex dump, but I seem to recall that character encodings for UTF-8 treated as something else will create extra characters (which aren't really there).

0

精彩评论

暂无评论...
验证码 换一张
取 消