Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Valid XML names

 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following are the rules of valid XML names:

Element names are case sensitive.
Must begin with letter or underscore(_).
After initial character following are allowed
digits
period(.)
hyphen(-)
underscore(_)
colon( - legal but should be used except for namespaces
NO other characters are allowed like #, @, $, %
Element names cannot begin with xml, Xml, XMl, XmL, xML, xMl

1. Are there any other rules? If yes, please let me know.
2. About the last rule, I tried the following element names in XML Spy it allows me. Can I have a tag name that starts with XML or am I missing something.

<Root attr1="val1">
<xml></xml>
<xmlExtension></xmlExtension>
</Root>
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vasim Patel:
Following are the rules of valid XML names:


2. About the last rule, I tried the following element names in XML Spy it allows me. Can I have a tag name that starts with XML or am I missing something.

<Root attr1="val1">
<xml></xml>
<xmlExtension></xmlExtension>
</Root>


XML names starting with "XML" in any case combination are reserved by W3C for future standardization. So even though tehre is no rule , it is good practice to not have elemnts starting with xml, as in the future they might be processes differently by the XML processors once w3c comes up with special elemnts strating with "XML"!

here is the quote from w3c.org

"A Name is a token beginning with a letter or one of a few punctuation characters, and continuing with letters, digits, hyphens, underscores, colons, or full stops, together known as name characters. Names beginning with the string "xml", or any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification. "


W3C link see Section 2.3

HTH
 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Hari. I understand there is no rule for strings starting with xml.
Pls check the mock test link:
(http://www.javaranch.com/xml/XMLexamList.jsp
Core XML (by Mapraputa Is))

I came across a question
10. Which of the following strings are a correct XML name?
a) xmlExtension
b) xslNewElement
c) XMLElement#123
d) myXMLElement123

where b and d are answers.
What do they mean by correct? Do they mean valid?
All the above 4 are valid but 'a' and 'c' do not follow the naming conventions of w3c. what is the correct answer from the exam point of view.
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vasim Patel:
Thanks Hari. I understand there is no rule for strings starting with xml.
Pls check the mock test link:
(http://www.javaranch.com/xml/XMLexamList.jsp
Core XML (by Mapraputa Is))

I came across a question
10. Which of the following strings are a correct XML name?
a) xmlExtension
b) xslNewElement
c) XMLElement#123
d) myXMLElement123

where b and d are answers.
What do they mean by correct? Do they mean valid?
All the above 4 are valid but 'a' and 'c' do not follow the naming conventions of w3c. what is the correct answer from the exam point of view.



Since they are reserved by W3C, I will suiggest that they are invalid names So the correct answers from teh exam point of view will still be "b" and "d"

We have to go with W3C here ..the exam is based on ther specification !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic