XML technologies / XML / XML in a Nutshell / XML basics / XML names
(Excerpt from "XML in a Nutshell" by Elliotte Rusty Harold & W. Scott Means)
The XML specification is sometimes overly precise and fussy, yet it tries to be efficient wherever possible. One approach is to reuse rules for different things. For example, XML element names follow the same rules as attribute names and several less common constructs. These are collectively called XML names.
Element names and other XML names may contain essentially any alphanumeric character, including the usual English letters A through Z and a through z and digits 0 through 9. They may also include non-English letters, numbers, and ideographs such as ö, ç, Ω, and 串. Three punctuation characters are also allowed:
_ (underscore)
- (hyphen)
. (period)
Other punctuation, such as quotation marks, apostrophes, dollar signs, parentheses, percent signs, and semicolons, is forbidden in XML names. The colon is allowed, but reserved for Namespaces as discussed in Namespaces. XML names must not contain whitespace of any kind: ordinary spaces, carriage returns, line feeds, nonbreaking spaces, or similar characters. Furthermore, all names containing the letter sequence XML in any combination of uppercase and lowercase are reserved for standardizing XML-related W3C specifications.
Note: The main new feature in XML 1.1 is that XML names may contain characters first defined in Unicode 3.0 or later. XML 1.0 is limited to characters defined in Unicode 2.0. Additional scripts allowed in XML 1.1 names include Burmese, Mongolian, Thaana, Khmer, Yi, and Amharic. (All these scripts are already allowed in XML 1.0 text content; they just cannot name elements, attributes, or Entities.) For developers who do not need these scripts in markup, XML 1.1 offers little or no benefit.
XML 1.1 also allows unusual symbols in names, such as the musical symbol for a six-string fretboard, and about a million code points not currently assigned to any character. Using these would be unwise. Even in XML 1.1, we strongly recommend restricting names to letters, digits, ideographs, and the explicitly allowed ASCII punctuation.
XML names must begin with a letter, ideograph, or underscore, never a digit, hyphen, or period. Element names and other XML names have no length limit. Thus, the following elements are all well-formed:
<KFZ-Kennzeichen>K-LM 1002</KFZ-Kennzeichen><Tag-Monat-Jahr>23/7/2001</Tag-Monat-Jahr><vorname>Alan</vorname><_4-lane>I-610</_4-lane><téléphone>011 33 91 55 27 55 27</téléphone><ονομα>Melina Merkouri</ονομα>
These elements are not allowed:
<Driver's_License_Number>98 NY 32</Driver's_License_Number><Tag/Monat/Jahr>23/7/2001</Tag/Monat/Jahr><first name>Alan</first name><4-lane>I-610</4-lane>
Copyright © 2005 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from the book "XML in a Nutshell" is subject to the same conditions as the printed edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O’Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de
back to top