Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 37,775 times

Contents

Related Categories

Understanding XML Namespaces - Namespaces & Attributes

shohoudy

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/"
xmlns:py="http://www.developerfusion.com/schemas/payroll/">
<employee>
    <id>49982</id>
    <name>Bart Simpson</name>
    <hireDate>2000-07-04</hireDate>
    <py:salary py:value="4000765.00"></py:salary>
    <py:taxes>3980765.27</py:taxes>
</employee>
</employees>

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">
</employee>

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.

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 Systems Engineer for IBM and a Chief Architect for Best Software (now Sage Software). Now an independent consultant and trainer, Yasser specializes in XML and Web services and has authored a book on Web Services for Addison Wesley. A Microsoft Most Valuable Professional (MVP) for ASP.NET, Yasser speaks at industry conferences including VS Live and VS Connections and his articles appear regularly in VSM, XML Magazine, and MSDN Magazine. Yasser also publishes the monthly .NET Web Services newsletter.

Comments

  • Multiple namespace prefix from same URI

    Posted by yodha on 26 Jul 2005

    Hi,
    I'm having a problem with xml namespaces.
    My application accepts an xml document from another application, which is then validated using an xsd. The xsd has a namespace defined and uses a prefi...

  • Thank You

    Posted by rakeshmoza on 11 Feb 2005

    Just to say thank you for this article. I have just started learning xml. And after reading this article, I am clear in namespaces atleast.

  • Posted by lars_huttar on 30 Dec 2004

    Glad you found the answer.

  • Posted by puthurjamesaustin on 29 Dec 2004

    The beloe format gives the required o/p



    hi i got the o/p for it

    Posted by puthurjamesaustin on 29 Dec 2004


    The beloe format gives the required o/p



       

    Related Content

  • Extensible Markup Language (XML) Tutorial