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

XML namespace Declaration doubt

 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any one tell me the difference betrween following three examples.
And which prefix and attribute they are talking about can any onme explain me.

1.<!-- Declares two XML namespaces. Their scope is the A and B elements. -->
<A xmlns:foo="http://www.foo.org/" xmlns="http://www.bar.org/">
<B>abcd</B>
</A>
2.<!-- A and B are in the http://www.foo.org/ namespace,
which is associated with the foo prefix. -->
<foo:A xmlns:foo="http://www.foo.org/">
<foo:B>abcd</foo:B>
</foo:A>
3.<!-- This is equivalent to the previous example but uses
a default namespace instead of the foo prefix. -->
<A xmlns="http://www.foo.org/">
<B>abcd</B>
</A>
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example 1: Both elements do not use a prefix so they use are in the default namespace (which becomes active in the element it is declared in, until it is overridden in a nested element) - {http://www.bar.org/} declared with xmlns="http://www.bar.org/. The namespace {http://www.foo.org/} is also declared with xmlns:foo="http://www.foo.org/" and assigned to the prefix "foo" - however no element in the example uses it.


Example 2:No default namespace has been declared. So any elements without a prefix would not belong to any XML namespace. However the namespace {http://www.foo.org/} is declared with xmlns:foo="http://www.foo.org/" and assigned to the prefix "foo" which is used by all the elements shown.


Example 3: This example has a default namespace, {http://www.foo.org/} declared with xmlns="http://www.foo.org/". Therefore all unprefixed elements belong to the default namespace {http://www.foo.org/} which leads to a result that is identical to example 2.
 
Divya Gehlot
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peer,
Thanks for your help.
Though I cleared my doubts but still have some confusion.
Can you just help me in that
following are my queries--
Example 1:
In element A also we are just declaring the namespace and have the prefix "foo" then howcome its using default namespace.
I mean the element where we declare namespace should also use prefix.

Whats the difference between example 2 & 3 and whats the use of prefix in example 2 then if we have only one namespace declaration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic