This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

XML namespace Declaration doubt

 
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>
 
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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic