Node Names

Node Names

Most nodes have namesin fact, there are three different types of names that XPath uses:

  • Qualified names, also called QNames This term comes from, and it's the name of the node including any applicable namespace prefix. For example, the element <STARS> has the QName "STARS", and the element <map:STARS> has the QName "map:STARS".

  • Local name The local name is the same as the QName minus any namespace prefix. For example, the element <STARS> has the local name "STARS", and the element <map:STARS> also has the local name "STARS".

  • Expanded name If a node has both a local name and is associated with a namespace, its expanded name is made of a pair of the namespace's URI and the local name.


How does the expanded-name pair work, exactly? That's still an open question. There are XPath functions to return a node's local name and QName, but none to return its expanded name. The editor for the XPath 1.0 specification, James Clark, says at that the expanded name is made up of the namespace URI, a "+", and the local name, like this: . In fact, XPath processors are more likely to use the format {}planets . So the real answer here isit's still up to the software you're using.

The most common names are qualified names (QNames) and local names.

Here's how to find the various names for the different types of nodes:

  • Root nodes The root node's local name is an empty string, "". It does not have an expanded name.

  • Element nodes An element node has a local name that is simply the name of the element without any namespace prefix, a QName that includes any namespace prefix, and an expanded name computed by expanding the QName of the element with the applicable namespace URI.

  • Attribute nodes Like elements, attributes have local names, QNames, and expanded names. But here's something to notethe namespace prefix of the color attribute in <my:planet color="RED"> is not my there is no namespace prefix for this attribute. (In the QName and expanded name for attributes, you only use the actual namespace prefix for the attribute itself, not the element it's an attribute of.)

  • Processing instruction nodes The local name is the processing instruction's target. For example, in the processing instruction <?xml-stylesheet type="text/xsl" href="ch01_02.xsl"?> , the local name is xml-stylesheet . Because processing instructions don't have namespaces, the namespace part in processing instruction QNames and expanded names is null .

  • Comment nodes A comment node does not have a local name, a QName, or an expanded name.

  • Text nodes A text node does not have a local name, QName, or expanded name.

  • Namespace nodes The local name of a namespace node is the namespace prefix itself. A namespace node has an expanded name and QName as wellthe local part is the namespace prefix, and the namespace URI is always null .

Besides node names, XPath also specifies that nodes have string values .

XPath. Navigating XML with XPath 1.0 and 2.0 Kick Start
XPath Kick Start: Navigating XML with XPath 1.0 and 2.0
ISBN: 0672324113
EAN: 2147483647
Year: 2002
Pages: 131

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: