Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help: questions about namespace

 
roger wong
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have some questions about namespace, which have made me stuck. Could you please help answer them?
Thank you in advance!
Q1.
<book xmlns:h="http://book.com">
<h:title>java</h:title>
<h:author>sun</h:author>
<desc>javajava</desc>
</book>

Is <book> in the namespace of "http://book.com"? If not, what's its namespace?(is there a default namespace?)
Is <desc> in the namespace of "http://book.com"? If not, what's its namespace?

Q2. What's the namespace?
<book>
<title>java</title>
<author>sun</author>
<desc>javajava</desc>
</book>





 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1. Is <book> in the namespace of "http://book.com"?

No. The element happens to also declare that namespace, but it declares that it has the prefix "h". It doesn't use that prefix so it isn't in that namespace. And no, there isn't a default namespace because the document doesn't declare one. The element is in no namespace.

Q1. Is <desc> in the namespace of "http://book.com"?

No. Just like the book element, it is in no namespace. The http://book.com namespace is still in scope for that element, since it's inherited from its parent element, but again it isn't used by the desc element.

Q2. What's the namespace?

There isn't one.

You could read this tutorial which explains the whole thing in one page.
 
roger wong
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! That really helps!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic