SCDJWS Study Guide: XML Namespace


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

Uniqueness of Attributes

The W3C "Namespaces in XML" specification places restrictions on setting the name and namespace of an attribute. No tag can contain two attributes with identical names, or with qualified names that have the same local name and have prefixes that are bound to identical namespace names.

For example, each of the bad start-tags is illegal in the following:

<!-- http://www.w3.org is bound to 
	n1 and n2 -->
<x xmlns:n1="http://www.w3.org"
   xmlns:n2="http://www.w3.org" >
<bad a="1" a="2" />
<bad n1:a="1" n2:a="2" />
</x>

However, each of the following good tag is legal, because the default namespace does not apply to attribute names:

<!-- http://www.w3.org is bound to n1 and is the default -->
<x xmlns:n1="http://www.w3.org"
   xmlns="http://www.w3.org" >
<good a="1" b="2" />
<good a="1" n1:a="2" />
</x>


Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |