问题
I notice that when I configured the XML file values with "&" character , then XML file not open correctly
I guess this is because XML file values should not have some character as &
And "&" Should not set as value in the XML file
Please advice if there are more characters that should not set in the XML as value? ( or maybe & character is the only the one ?? )
Example of bad value from XML "&"
<FolderPath>\EEA\E1\C & W 100\AWQ</FolderPath>
Example of right line from XML
<FolderPath>\EEA\E1\C and W 100\AWQ</FolderPath>
回答1:
I would refer you to: http://www.w3schools.com/xml/xml_syntax.asp
Some characters have a special meaning in XML.
If you place a character like "<" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
There are 5 pre-defined entity references in XML:
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
You can verify your XML with: http://www.w3schools.com/xml/xml_validator.asp
回答2:
The safe thing to do is to always escape as follows:
& ⇒ &
< ⇒ <
> ⇒ >
" ⇒ "
' ⇒ '
Detailed answer:
&is special in element text and attribute values. Use&instead.<is special in element text. Use<instead.>is not special by itself."is special in attribute values delimited by". Use"instead.'is special in attribute values delimited by'. Use'instead[1].]]>is special in element text. Use]]>instead.]]>is special inCDATAsections. Use]]>]]><![CDATA[instead.--can't be used in comments.- Only the following characters can be found in XML: 0x0009, 0x000A, 0x00D, 0x0020..0xD7FF, 0xE000..0xFFFD, 0x10000..0x10FFFF. There is no way to include the others.
&, <, >, " and ' can always be used in element text and attribute values even when it's not necessary to do so, so the safe thing to do is to always escape &, <, >, " and '. (Alternatively, always escape all of them except single quotes, and never use single quotes as the delimiter for attribute values.)
- In HTML, you have to use
'instead. An old version of Internet Explorer accidentally didn't support'for XHTML (XML-based HTML) either. As such, some people use'for XML too.
来源:https://stackoverflow.com/questions/28480412/which-character-should-not-be-set-as-values-in-xml-file