Node String Values

In addition to giving most nodes names , each node in XPath is considered to have a string (that is, text) value. For example, the string value of a comment node is the simple text content of the comment itself. Here's how to get the string value for each of the various types of nodes:

  • Root nodes The string value is the concatenated (joined) string value of all text nodes.

  • Element nodes The string value is the concatenated value of all contained text nodes, including the text nodes in descendant elements.

  • Attribute nodes The string value is the normalized attribute value. (The normalized value of a text string is the same text with leading and trailing whitespace removed, as well as converting multiple consecutive whitespace into a single whitespace characterunless the text string is considered XML character data, CDATA, in which case whitespace is not removed.)

  • Processing instruction nodes The string value is everything in the processing instruction between the target and the closing ?> . For example, in the processing instruction <?xml-stylesheet type="text/xsl" href="ch01_02.xsl"?> , the string value is "type="text/xsl" href="ch01_02.xsl" .

  • Comment nodes The string value is the comment's content.

  • Text nodes The string value is simply the character data in the text node.

  • Namespace nodes The string value is the namespace URI.

For example, take a look at this short XML document:

 
 <?xml version="1.0"?>  <!--Here are the words--> <words copyright = "(c) 2003 Starpowder Inc.">     <term>Hello</term>     <term>there.</term> </words> 

The string value of the root node of this XML document is the joined string value of the document's text nodes. That looks like this (including whitespace) :

 
 Hello there. 

So far, then, we've seen how XPath views the nodes in an XML document. But how are those nodes arranged? There are a few different ways of looking at the order of nodes in an XML document, and the first one we should discuss is document order .



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

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net