The optional fourth argument specifies the number of characters to select. The example below, selects the ‘737’ from the first occurrence of the entire string Boeing737:

xpointer(string-range(/,"Boeing737",7,3)[position()=1])

If the first string argument in the node test is empty, then relevant positions in the context node's text contents are selected. In the example below, the first six characters are picked up:

xpointer(string-range(/,""1,6)[position()=1])

See Related Publications.

2.6 XPath

XPath is to address parts of an XML document. Xpath supports XML namespaces because XPath models an XML document as a tree of nodes (root nodes, element nodes, attribute nodes, text nodes, namespace nodes, processing instruction nodes, and comment nodes). The basic syntactic construct in XPath is the expression. An object is obtained by evaluating an expression, which has one of the following four basic types:

￿Node-set (an unordered collection of nodes without duplicates)

￿Boolean

￿Number

￿String

XPath uses path notation to define locations within a document. The paths starting with a “/” signifies an absolute path. A simple example of this is shown below.

Let us consider an XML document (Library.xml) which describes a Library System. This sample document will be used throughout XPath and XPointer for examples.

Example 2-6 An XPath example

<? xml version=”1.0”?>

<!DOCTYPE LIBRARY SYSTEM “library.dtd”> <LIBRARY>

<BOOK ID=”B1.1”> <TITLE>xml</TITLE> <COPIES>5</COPIES>

</BOOK>

<BOOK ID=”B2.1”> <TITLE>WebSphere</TITLE> <COPIES>10</COPIES>

Chapter 2. Technologies in XML 33

Page 49
Image 49
IBM Version 5 manual Example 2-6 An XPath example