Understanding XML Namespaces

Namespaces & Attributes

You can prefix attributes names with a namespace prefix just like element names. For example, in the following snippet, the value attribute of the <salary> element belongs to the payroll namespace http://www.developerfusion.com/schemas/payroll/:

<employees xmlns="http://www.developerfusion.com/schemas/hr/"
    <name>Bart Simpson</name>
    <py:salary py:value="4000765.00"></py:salary>

However, default the namespaces does not apply to attribute names. For example, in the following snippet, the id attribute does not belong to any namespace even though there’s a default namespace declared:

<employee xmlns="http://www.devxpert.com/schemas/hr/" id="90385">

I hope that this article has helped you understand XML Namespaces and how they work. If you’re not familiar with XSD schemas, stay tuned for my upcoming articles on this topic. Learning XSD will help you fully understand XML Namespaces.

You might also like...


About the author

Yasser Shohoud United States

Yasser started programming at the age of 12 when he wrote his first text-based game on a Commodore PET. He's since moved to IBM mainframes then to Microsoft technologies and has worked as System...

Interested in writing for us? Find out more.


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“My definition of an expert in any field is a person who knows enough about what's really going on to be scared.” - P. J. Plauger