Search code examples
xmlspecial-characters

XML special characters in text node


I'm producing a XML file and need to know if I can have ' " characters in the text node of a XML element.

like:

<root>
   <location>48°51'24"N 2°21'03"E</location>
</root>

I've read: w3c xml syntax and character entity reference. And cannot figure out what applies to my situation.

If I validate this in a xml www.w3schools.com/xml/xml_validator.asp it's valid. Do I need to convert this to &apos;? If yes, why?


Solution

    1. Yes you can.
    2. &apos; is valid here too, but not necessary. It would be necessary if you had <location coords='48°51&apos;24"N 2°21'&apos;03"E'/> to distinguish the apostrophes in text data from the apostrophes delimiting the attribute value.
    3. Strictly you should use prime and double-prime for minutes and degrees of arch, single and double-quote is a kludge from the ASCII-only days. You can also use &#x2032; and &#x2033 for those - no technical reason, it's just easier to type and won't choke if it passes through an ASCII-only system en route.