当前位置: 动力学知识库 > 问答 > 编程问答 >

xml cdata returns XML parsing failed: syntax error illegal byte sequence in encoding with xslt

问题描述:

i searched for an answer and couldn't find one.

i have a long xml generated by server. i want to display some of the nodes using xslt.

the problem is: when i open the xml on browser i get:

XML parsing failed,XML parsing failed: syntax error,illegal byte sequence in encoding

the error is inside a cdata inside one of the nodes staring with <![CDATA[ and ends with ]]>

the error is: , and a hundreds of characters like it.

to my understanding this shouldn't happen if its in cdata it should ignore or escape it.

the xml encoding is utf8 .

thank you for your help.

网友答案:

The encoding

You say "the xml encoding is utf8". Your parser is telling you that you're wrong. It's finding a byte sequence that cannot occur in UTF-8; in my experience that often happens when ISO 8859-1 (ISO Latin 1) data is wrongly tagged UTF-8.

If you have examined the data in question in a hex dump or similar tool and confirmed that it's legal UTF-8, then it looks like you have a bug to report to your vendor. If you haven't, then it says here the parser is likely to be right, and your data is unlikely to be UTF-8. Find out what it is, and declare it correctly, or fix the configuration of the server to make it produce a UTF-8 data stream, or use a character-encoding conversion utility to convert the server's output to UTF-8.

CDATA sections

CDATA sections occur within a character sequence being parsed as XML; they declare that their contents are character data and not XML delimiters. A CDATA section does not and cannot declare that its content is an arbitrary sequence of bits, bytes, or octets; by the time a sequence of characters is recognized as a CDATA section, the bits in the encoding of the data stream have already been converted to characters; it's too late to say "Don't parse these octets as characters!"

分享给朋友:
您可能感兴趣的文章:
随机阅读: