A namespace binding (special xmlns
or xmlns:...
attribute) is in scope for all the descendants of the enclosing element, including this element.
<?xml version="1.0"?>
<root>
<my:element xmlns:my="http://www.example.com/ns1">
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
</my:element>
<my:element xmlns:my="http://www.example.com/ns2">
<!-- here, the prefix my is bound to http://www.example.com/ns2 -->
</my:element>
</root>
The binding can be overriden in a nested element (this affects readability though):
<?xml version="1.0"?>
<my:element xmlns:my="http://www.example.com/ns1">
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
<my:first-child-element/>
<my:child-element xmlns:my="http://www.example.com/ns2">
<!-- here, the prefix my is bound to http://www.example.com/ns2,
including for the element my:child-element -->
</my:child-element>
<!-- here, the prefix my is bound to http://www.example.com/ns1 -->
<my:last-child-element/>
</my:element>
It is very common to declare all namespace bindings in the root element, which improves readability.
<?xml version="1.0"?>
<root
xmlns="http://www.example.com/default-namespace"
xmlns:ns1="http://www.example.com/ns1"
xmlns:ns2="http://www.example.com/ns2">
<ns1:element>
<ns2:other-element/>
</ns1:element>
</root>