About XPath
XML Path Language (XPath) is a query language that is used to search for and retrieve information contained within the nodes of an XML document. In Microsoft Office InfoPath 2003, these nodes equate to fields or controls on a form. XPath queries are formed as expressions. These expressions are used to address the various parts of an XML document, to manipulate strings, numbers, and Boolean values, and to match a set of nodes within the document.
XPath views an XML document as a tree of different node types. XPath expressions identify these nodes in the XML document based on their type, name, and values, as well as the relationship of a node to other nodes in the document. An XPath expression yields one of the following basic objects:
- Node set A collection of nodes that match the expression. Node types include root (document), element, attribute, namespace, processing instruction, comment, and text.
- Boolean A true or false value.
- Number A numerical value.
- String A text value.
XPath expressions are formed by using patterns that specify the location path of a node or set of nodes, and that are relative to the context node. The context node is the section of the XML document from which you are currently positioned. It is represented in XPath as a period (.). XPath also supports the use of patterns that have absolute locations based on the document root. The document root is represented in XPath as a forward slash (/).
In addition to location paths, XPath has a number of functions that can be used to retrieve data from an XML document. The following is a list of the types of functions that XPath supports:
- Node Used for working with the various node types. Examples of node functions include name, node, processing-instruction, comment, and text.
- Positional Used for nodes that belong to a node set. These functions determine or match the position of the nodes. Examples of positional functions include name, id, last, and count.
- Numeric Used to return numeric values. Examples of numeric functions include ceiling, floor, number, round, and sum.
- Boolean Used to evaluate XPath expressions to true or false. Examples of Boolean functions include boolean, false, not, and true.
- String Used to manipulate and parse string text. Examples of string functions include concat, contains, starts-with, string, substring, and translate.