0

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>
maihabunash
  • 1,632
  • 9
  • 34
  • 60

2 Answers2

5

The safe thing to do is to always escape as follows:

&  ⇒  &amp;
<  ⇒  &lt;
>  ⇒  &gt;
"  ⇒  &quot;
'  ⇒  &apos;

Detailed answer:

  • & is special in element text and attribute values. Use &amp; instead.
  • < is special in element text. Use &lt; instead.
  • > is not special by itself.
  • " is special in attribute values delimited by ". Use &quot; instead.
  • ' is special in attribute values delimited by '. Use &apos; instead[1].
  • ]]> is special in element text. Use ]]&gt; instead.
  • ]]> is special in CDATA sections. Use ]]>]]&gt;<![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.

&amp;, &lt;, &gt;, &quot; and &apos; 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.)


  1. In HTML, you have to use &#39; instead. An old version of Internet Explorer accidentally didn't support &apos; for XHTML (XML-based HTML) either. As such, some people use &#39; for XML too.
ikegami
  • 367,544
  • 15
  • 269
  • 518
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:

&lt;    <   less than
&gt;    >   greater than
&amp;   &   ampersand 
&apos;  '   apostrophe
&quot;  "   quotation mark

You can verify your XML with: http://www.w3schools.com/xml/xml_validator.asp

Community
  • 1
  • 1
Sobrique
  • 52,974
  • 7
  • 60
  • 101