• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Namespace in XML

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please look at the following XML chunk from Skonnard e-Book.
<p erson xmlns ="http://someURI">
<name>Martin</name>
<age>33</age>
</p erson>
It is explained in the book that, whereas Person is qualified element but child-elements name and age are unqualified elements.
How can it be so? I feel that the above child elements ALSO should be qualified as they are in-scope namespace of their parent.
Any suggestion please?? :roll:
 
Rajesh Pathak
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the above XML seems to be unreadable, please refer this one...My question remains the same.
<s:student xmlns ="http://someURI">
<name>Martin</name>
<age>33</age>
</s:student>
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Referring to the example you have given, the parent element student belongs to a namespace whose prefix is "s",whereas the child elements belong to the default namespace that you have declared ie: xmlns ="http://someURI">.
<s:student xmlns ="http://someURI">
<name>Martin</name>
<age>33</age>
</s:student>
An unqualified element refers to an element that does not have a prefix attached,however it can still belong to a namespace.
Normally, the scope of a namespace is the element that includes it and its child elements.
Hence in your example, name and age are unqualified because they are not written as
<s:name> and <s:age>,but they still belong to a namespace.
Since you have declared xmlns ="http://someURI" without a prefix,so it makes this URI as the default namespace.Now any element declared without a prefix will belong to this default namespace.
Hope this helps.
Vasudha
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rajesh's two posts are actually different from my aware of JavaRanch's famous smiley effect.
However, Vasudha's explanation is correct conceptually on both. Even those unqualified elements will belong to a different namespace.
Use &#58; to post : will avoid the JavaRanch's famous smiley effect.
In JavaRanch:
:p will become a
:o will become a
:D will become a
I reversed the JavaRanch effect to read Rajesh's first code, then I know it is different than the second one from namespace point of view.
Roseanne
[ November 17, 2002: Message edited by: Roseanne Zhang ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic