Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Developer's Guide

Navigating Along the child Axis

The child axis selects nodes that are immediate children of the context node. For example, if the context node is the root <chairman> element:

child::president

locates a node set consisting of two <president> elements:

Assuming the same context node, changing the location step to:

child::president | child::name

will locate a node-set consisting of the above two elements and the <name>Kim Akers</name> element.

Only the root node and element nodes in a document have nodes along the child:: axis. This means that, comments, attributes, processing instructions (PIs), and namespaces do not have children. Similarly, only element nodes may be located along the child:: axis if you use a name node test, such as a specific element name, or * for all elements. If you need to select comments and PIs as well, use the node() or other node-type test. For example:

child::node()

locates all comments and PIs which are children of the context node, as well as all element children, while:

child::comment()

locates all comments which are children of the context node, while excluding all PI and element nodes.

The child:: axis is the default, if no axis is supplied in a location step. Therefore, the following are equivalent:

child::name
name

See Also

Sample XML File for Navigating XPath Axes | Constructing the Node-Test Portion of a Location Step