What characters are not allowed (if they are not encoded) in the XML attribute?

I can’t believe that I can’t easily find this information, therefore:

1) What characters cannot be included in an XML attribute without an encoding entity?

Obviously you need to encode quotes. What about < i > ? What else?

2) Where exactly is the official list?

+41
xml xml-serialization
May 15, '09 at 2:00
source share
3 answers

Here is a definition of what is allowed in the attribute value .

 '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'" 

So you cannot:

  • the same character that opens / closes the attribute value (either ' or " )
  • naked ampersand ( & should be &amp; )
  • left angle bracket ( < must be &lt; )

You should also not use characters that are not explicitly legal anywhere in the XML document (e.g. form feeds, etc.).

+48
May 15 '09 at 3:45
source share

According to the current (2) current recommendation , especially regarding character data and Markup , these are: (1) ampersand (&), left corner bracket (<), bracket in the right corner (>) and as a single quote ("), and double quotation mark (").

+5
May 15 '09 at 2:17
source share

See 2.2 Characters in Extensible Markup Language (XML) 1.0 (Third Edition) .

Note that, at least with .NET, if you use the XML API to work with XML, you do not have to worry about that. This is the reason not to treat XML as text.

+1
May 15 '09 at 2:06 a.m.
source share



All Articles