XML name space


I have something like ,
<document xmlns="http://www.businessobjects.com/2003/ro" xmlns:ro="http://www.businessobjects.com/2003/ro" unit="pixel">

on top of my xml.
Can nay one please explain what it is?
why we use namespace? etc

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Name spaces confused me for a while, they are really meant to separate different elements or group them together.  In this case ro is set to the namespace name which would prefix in the opening XML element tag belonging to it.  This can be helpful for validating rules you might have.  This may be of help:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SameerMirzaAuthor Commented:
Thanks, I understand namespace definition, usage, possible way to use it, by reading the link you reffered but still dont understand how to actually use it.

I mean ok it help to distingwish between two elements with the same name but why do we have a URL attached to NAMESPACE?

It would be very helpful if some one could provide more details.

Gertone (Geert Bormans)Information ArchitectCommented:
that is not necessarily a URL by the way, but a URI, a UNIVERSAL RESOURCE IDENTIFIER,
that is an unique identifier that tells us exactly what namespace this is
As the for of the URI, often a URL syntax is choosen, because the owner of a domain can assume noone else will pick his domain as part of a URI
It gives you more garantuee that your namespace is unique

<foo:bar xmlns:foo="foo-namespace"/>

is valid as well, here I have chosen "foo-namespace" as the URI for my namespace,

note that the namespace binding is important (the URI), not the prefix.
A prefix has no meaning in XML

<foo:bar xmlns:foo="foo-namespace"/>
<xsl:bar xmlns:xsl="foo-namespace"/>
<xsd:bar xmlns:xsd="foo-namespace"/>
<html:bar xmlns:html="foo-namespace"/>
<bar xmlns="foo-namespace"/>

all mean the same element in the same namespace (XML wise they are exactly the same)
Note that I have used some confusing prefixes, just to show you that  prefix only has a meaning in combination with a binding
Here is a non-technical explanation...

You are speaking to a crowd... you raise your right hand when you are speaking English, and raise your left hand when you're speaking French.  This signaling lets the audience know when you are switching bewteen languages.   If the crowd is mostly English speaking, you might be able to perform a shortcut and only use your left hand when speaking French (since it is assumed that the rest of the conversation is in English).

That's what namespaces are all about... they allow you to tell the XML parser when you're switching between a markup language that it knows about to another markup language that it might not know about.  And just like the silly example above, you can have a default language and only use the namespaces when the "foriegn" language appears.

One of the main purposes for namespaces is to help the XML parser to validate the document (like performing a spelling and grammer check).  As you can imagine, the XML parser really needs to know the language in order to valide the spelling/grammer (since the rules for English are lot different that French).

As for you the coder... namespaces are not that exciting.   They are not something that you'd normally use to accomplish a task (unless you're writing the spelling/grammer check logic).  But, you still would have to use namespaces to keep your document from failing validation.
SameerMirzaAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.