What are the official XML reserved characters?
Asked Answered
E

2

8

In this page, Microsoft says that XML reserved characters (and their entity) are the following ones:

>    >
<    &lt;
&    &amp;
%    &#37;

But in this other page, I found that also ' is a reserved character (and its entity is &apos;).

Can someone indicate me some official reference in which are listed all and only the XML reserved characters?

Equestrian answered 13/2, 2014 at 15:23 Comment(2)
Please read for context. The two articles are about different things, and only one is from Microsoft.Blakeslee
I didn't say that the second is by Microsoft...Equestrian
R
15

According to the XML spec, the only characters that must be escaped when used as character content rather than markup are & (as &amp;, &#38; or &#x26;) and < (as &lt;, &#60; or &#x3C;), plus > when it is part of the sequence ]]>. In addition, single quotes must be escaped (typically as &apos;) in single quoted attribute values, and double quotes (typically as &quot;) in double-quoted attribute values, and any character that is not representable in the character encoding used to serialize the document must be escaped as a suitable character reference.

You don't have to escape double quotes in single quoted attributes or vice versa, but it won't do any harm if you do so.

Of course, you may escape every >, " and ' (and any other character) within character content if you want to, without changing the meaning.

Rossen answered 13/2, 2014 at 15:28 Comment(1)
The reason "%" is present in the Microsoft list is probably because "%" is reserved in certain contexts within the DTD.Tryma
D
5

XML doesn't have any notion of "reserved characters".

It has predefined entities which represent the most of the characters which may (depending on context) have special meaning in an XML document (", <, >, & ').

It doesn't have named entities for the space character or = because the places where they have special meaning are places that you can't have data.

Diagnosis answered 13/2, 2014 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.