XML - 根级别的数据无效 [英] XML - Data At Root Level is Invalid
问题描述
我有一个以 UTF-8 编码的 XSD 文件,我运行它的任何文本编辑器都不会在文件的开头显示任何字符,但是当我在 Visual Studio 的调试器中将其拉出时,我清楚看到文件前面有一个空框.
我也收到错误:
根级别的数据无效.第 1 行,位置 1.
有人知道这是什么吗?
更新:编辑帖子以限定文件类型.它是由 Microsoft 的 XSD 创建者创建的 XSD 文件.
事实证明,答案是我看到的是一个 中打开它:,并进行,那么我可能就没有这个问题了.
I have an XSD file that is encoded in UTF-8, and any text editor I run it through doesn't show any character at the beginning of the file, but when I pull it up in Visual Studio's debugger, I clearly see an empty box in front of the file.
I also get the error:
Data at the root level is invalid. Line 1, position 1.
Anyone know what this is?
Update: Edited post to qualify type of file. It's an XSD file created by Microsoft's XSD creator.
It turns out, the answer is that what I'm seeing is a Byte Order Mark, which is a character that tells whatever is loading the document what it is encoded in. In my case, it's encoded in utf-8, so the corresponding BOM was EF BB BF
, as shown below. To remove it, I opened it up in Notepad++ and clicked on "Encode in UTF-8 without BOM", as shown below:
.
To actually see the BOM, I had to open it up in TextPad in Binary mode:, and conducted a Google search for "EF BB BF
".
It took me about 8 hours to find out this was what was causing it, so I thought I'd share this with everyone.
Update: If I had read Joel Spolsky's blog post: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!), then I might not have had this problem.
这篇关于XML - 根级别的数据无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!