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.
Comments