Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NMTOKEN vs ID

 
Nitin Gogia
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If attribute type declared as NMTOKEN or ID what values can both of them accept. In other words what is the difference between NMTOKEN and ID.
'12345-09' is a valid NMTOKEN but not valid ID. Because ID has to be XML name. Isn't this true with NMTOKEN ?
 
Karthik Jayaraman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note '12345-09' is not a valid XML name as the first character is a number (Name1 character restriction)
ID type attributes must fully comply to XML Name restrictions whereas Nametokens comply to all ex cept the Name1 char restriction for XML Names.
 
Nitin Gogia
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Karthik:
I did not get you when u say "NMTOKEN comply to all" except Name1 char restriction. Does it mean that NMTOKEN has to be in XML name syntax except that the 1st character can be a number, dot, hyphen etc.
 
Joel Amoussou
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Nitin,
The syntax of XML1.0 is expressed in EBNF to avoid ambiguity and confusion. The production for Name and Nmtoken are the following:
[4] NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
[5] Name ::= (Letter | '_' | ':') (NameChar)*
[7] Nmtoken ::= (NameChar)+
The EBNF notation is quite easy to learn. If you are not familiar with EBNF, I highly recommend that you read Section 6 of the XML specification which contain an EBNF primer.
Once you understand the EBNF notation, the grammar of XML1.0 becomes clear. Other specs like XPath are also expressed in EBNF. I always start my XML classes my explaining EBNF. My experience is that it works very well.

----------
Joel Amoussou
XML Instructor
IBM XML Certification Practice Test
http://www.xmlmentor.net/xmlexamsim.htm
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic