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></Foo>
Error 1 Character ' ', hexadecimal value 0x2 is illegal in XML documents. XMLFile1.xml 2 6 Miscellaneous Files
thanks in avdance, George
Your problem is the reference to , 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).
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   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   "is strongly discouraged".
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.
0x2 is not a printable character.
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