This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XML namespace doubt  RSS feed

 
Parth K
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Skonnard's book
1) "A namespace declaration is in scope for the element on which it is declared and all of that elements descendent"
<pre:person xmlns:pre='uri:example-org:people'>
<name>Martin</name>
<age>33</age>
</pre:person>
2) "The element Person has children with local names of name and age. Both of these child elements are unqualified; that is , they are not in any namespace."
WHY ? Isn't point 2 contradicting point 1 above ? OR is it that child elements are not considered as descendents of the parent element ?
Can someone throw some light on this.
Thanks,
Prasen
[ May 12, 2003: Message edited by: Prasen K ]
[ May 12, 2003: Message edited by: Prasen K ]
[ May 12, 2003: Message edited by: Prasen K ]
[ May 12, 2003: Message edited by: Prasen K ]
 
Karthik Jayaraman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The namespace "declaration" is for all the elements below it. That means you can use pre as a qualifier for all the elements below name element. The same cannot be done for parent of name (if it is not declared in any ancestor of it)
The scope of the declared namespace and its "use" is limited to the element(where the namespace is defined.) and all descendant's of it.
 
Karthik Jayaraman
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<ano:ancestor xmlns:ano="....">
<pre:child> <!--This is invalid-->
<pre:name xmlns: pre="....">
<pre:child1/>
<ano:child2/> <!-- This is valid-->
</pre:name>
</ano:ancestor>
In the above eg. the second line is an error as pre is only defined for "name" element and its descendant and cannot be used in a sibling element "child".
[ May 13, 2003: Message edited by: karthik jayaraman ]
[ May 13, 2003: Message edited by: karthik jayaraman ]
 
Parth K
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Karthik. Your explanation as well as example cleared my doubt.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!