invalid XML file?

瘦欲@ 提交于 2019-12-07 21:40:24

问题


I wrote the following file in Visual Studio 2008 as a new XML file, and it reports the following error. What is the error message about and why it is treated as a wrong format XML file?

Here is the XML file and related error message.

<?xml version="1.0" encoding="utf-8"?>
<Foo>&#x2;</Foo>

Error   1   Character ' ', hexadecimal value 0x2 is illegal in XML documents.   XMLFile1.xml    2   6   Miscellaneous Files

thanks in avdance, George


回答1:


Your problem is the reference to &#x02, which essentially is random binary data that can not be printed. This is not allowed in XML1.0 (it is in XML 1.1 and higher, but it's not certain that your .Net version will allow it even if you change XML versions).




回答2:


I wrote the following file in Visual Studio 2008 as a new XML file, and it reports the following error. What is the error message about and why it is treated as a wrong format XML file?

According to the W3C XML 1.0 Specification, the only characters allowed in an XML document that are below &#x20; are the tab (09), newline (0A) and carriage return (0D).

XML 1.1 allows almost all characters, excluding 00, but is very rarely implemented and one should not rely on finding an XML 1.1 implementation.

Even in the XML 1.1 Spec. it is said that the use of the now allowed characters below &#x20; "is strongly discouraged".




回答3:


Check out the XML 1.0 specification

In particular, see the definition of Characters in section 2.2:

Char ::= #x9 | 
         #xA |
         #xD |
         [#x20-#xD7FF] |
         [#xE000-#xFFFD] |
         [#x10000-#x10FFFF]

And the definition of entity references in section 4.1:

Characters referred to using character references must match the production for Char.




回答4:


0x2 is not a printable character.




回答5:


If you need to put binary data inside XML, use the CDATA section. http://www.w3schools.com/XML/xml_cdata.asp



来源:https://stackoverflow.com/questions/696424/invalid-xml-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!