Reputation: 86095
have an xml data like
<Item xmlns="http://www.sample.com">
<name>robert</name> ....
</Item>
want to know what is the default namespace here? Why we need an namespace here?
Upvotes: 2
Views: 63
Reputation: 243479
<Item xmlns="http://www.sample.com"> <name>robert</name> .... </Item>
want to know what is the default namespace here?
The default namespace is "http://www.sample.com". Whenever a namespace is defined without a prefix, this is a definition of a default namespace for the current elementand all of its descendents, unless somewhere in the subtree topped by the current element there isn't a new default namespace defined (in this case it will shadow the previously defined default namespace for the subtree on which the new default namespace definition was done).
Why we need an namespace here?
The main and only purpose of a namespace is to help distinguish identical names used in different subject areas.
For example: "item" of a sequence or "item" in an invoice; "book" to read or "book" a hotel.
Namespaces are necessary in any case when elements from two different XML documents covering different subject matters, must be combined into one single XML document -- booking a hotel and asking what books are in the hotel library may be an example.
Upvotes: 2