Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

xml parsing - An Invalid XML character(Unicode: 0x0) was found in the element content of the document error

I have an XML file which gives me the following error while parsing: An Invalid XML character(Unicode: 0x0) was found in the element content of the document error.

I can read the whole thing fine, and there are no control characters either.

But when I typed the whole thing myself instead of a file that was provided to me it worked fine.

What could be the issue. I read through some similar questions on SO and they all said that this might be a encoding issue. But can anyone elaborate on this as I could read the whole thing. And if it is encoding issue how would i know by looking at the file because it looks fine. Its readable. I delete a line and type it myself and that line is getting parsed properly.

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two possible explanations. Either the file contains an instance of the Unicode codepoint 0x0, correctly encoded. XML does not allow this character.

Alternatively, the parser thought it saw an instance of 0x0 because it was decoding the physical bytes of the file incorrectly: that is, the encoding assumed by the XML parser is not the actual encoding of the file.

When you're dealing with this kind of question you need to be very careful about phrases like "I can read the whole file" and "it looks fine". You can't actually see the bits on the disk, you can only use some kind of viewing tool to interpret them for you, and you need to be clear about what tool you were using and how it was configured.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...