Arch2Arch Tab BEA.com
Syndicate this blog (XML)

Resolving XML QNames

Bookmark Blog Post

del.icio.us del.icio.us
Digg Digg
DZone DZone
Furl Furl
Reddit Reddit

Alexandre Alves's Blog | November 11, 2005   5:49 PM | Comments (0)


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'

 


Comments

Comments are listed in date ascending order (oldest first) | Post Comment



Only logged in users may post comments. Login Here.

Powered by
Movable Type 3.31