How do I include &, <, > etc in XML attribute values How do I include &, <, > etc in XML attribute values xml xml

How do I include &, <, > etc in XML attribute values


You will have to escape

" to  "' to  &apos;< to  <> to  >& to  &

for xml.


In XML attributes you must escape

" with "< with <& with &

if you wrap attribute values in double quotes ("), e.g.

<MyTag attr="If a<b & b<c then a<c, it's obvious"/>

meaning tag MyTag with attribute attr with text If a<b & b<c then a<c, it's obvious - note: no need to use &apos; to escape ' character.

If you wrap attribute values in single quotes (') then you should escape these characters:

' with &apos;< with <& with &

and you can write " as is.Escaping of > with > in attribute text is not required, e.g. <a b=">"/> is well-formed XML.