XML Names

The XML 1.0 Recommendation places restrictions on the characters that may be used in legal XML names and imposes tighter restrictions on the characters that may be used as the first character in an XML name.

Initial Characters of XML Names

In English, the initial character of an XML name must be either a letter (from A to Z—both upper- and lowercase are legal), the colon character (:), or the underscore character (_).

Tip

Avoid the colon character as the first character in an XML name. Using that character is legal but could cause confusion when you create XML documents using elements from several XML namespaces (described in Chapter 8, “Namespaces in XML”).



XML is case sensitive, so the following two elements are considered in XML to be different elements because of the difference in case:

<p></p> 

<P></P> 

In some other languages, ideographic characters may also be used as the initial character of an XML name.

It is illegal to start an XML name with a numeric character. The following code generates an error because 2d is not a legal XML name:

<?xml version='1.0'?> 
<myElement> 
 <2d> 
  Some content. 
 </2d> 
</myElement> 

Caution

Names in XML 1.0 must not begin with the character sequence xml or XML, in any combination of upper- or lowercase.



All characters that are legal as the first character of an XML name can be used in later positions within an XML name as well.

Non-Initial Characters of XML Names

The non-initial characters of an XML name are allowed to include characters not permitted as the first character of an XML name. The additional allowed characters are numeric characters from 0 to 9 inclusive, the hyphen character, and the period character.

Tip

Again, avoid using the colon character later in XML names. Later you will want to mix XML documents from different namespaces (discussed in Chapter 8), and the colon character has special meaning in those circumstances. Avoiding the colon character except in namespace-aware documents means that you won’t have to change your documents if you want to use multiple namespaces later.



..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset