Resolving XML QNames

How does one expand a XML QName in the presence of default namespaces?

The XML Namespace specification defines the concept of a qualified name as a name consisting of a local part and namespace URI.

A qualified name, or QName, is specified in terms of a prefix and a local part (e.g. <foo:bar xmlns:foo=’urn:foo’>), where the prefix (foo) is resolved to a namespace URI (‘urn:foo‘).
This process of resolving the prefix results in what is commonly known as the expanded name.

The rules for resolving a prefix are mostly uniform in the context of different XML processors, with the exception of how default namespaces (e.g. xmlns=’urn:foo’) are dealt with.

Specifically:

 

  • XML elements: if the QName does not have a prefix, then the in-scope default namespace must be used.

XML

Resolved
namespace for element ‘foo’

<foo xmlns=’urn:foo’/>

‘urn:foo’       

 

  • XML attributes: if the QName does not have a prefix, then the namespace URI is NULL, that is, the default namespace is not used.

XML

Resolved
namespace for attribute ‘a’

<foo xmlns=’urn:foo’a=’attr1’/>

NULL

<foo xmlns:ns1=’urn:foo’ ns1:a=‘attr1’ />

‘urn:foo’

 

  • Attribute value of W3C Schema primitive type QName: if the QName does not have a prefix, then the in-scope default namespace must be used.

XML

Resolved
namespace of attribute value of attribute ‘a’

<foo xmlns=’urn:foo’ a=’myname‘/>

where

<xsd:attribute name=’a’ type=’xsd:QName’/>

‘urn:foo’

 

  • XSLT (1.0) variable or parameter: if the QName does not have a prefix, then the namespace URI is NULL, that is, the default namespace is not used.

XSLT

Resolved
namespace for variable

<xsl:variable name=’varA’ xmlns=’urn:foo’ />

NULL

<xsl:variable name=’ns1:varA’ xmlns=’urn:foo’
xmlns:ns1=’urn:bar’ />

‘urn:bar’

 

  • XPath 1.0 node tests: if the QName does not have a prefix, then the namespace URI is NULL, that is, the default namespace is not used.

XPATH

Resolved
namespace for Node Test ‘b’

<a xmlns:ns1=’urn:foo’ xmlns=’urn:foo’>
  <b/>
</a>

/ns1:a/b

NULL

/ns1:a/ns1:b

‘urn:foo’

 

  • XPath 2.0 node (name) tests: if the QName does not have a prefix, then the in-scope default namespace must be used.

XPATH

Resolved
namespace for Node Test ‘b’

<a xmlns:ns1=’urn:foo’ xmlns=’urn:foo’>
  <b/>
</a>

/ns1:a/b

‘urn:foo’

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: