Mega Code Archive

 
Categories / XML Tutorial / Xpath
 

Child Axis

The child axis is the  default axis in XPath.  The child axis selects nodes that are immediate child nodes of the context node.  <Invoice>      <Date>2008-01-02</Date>      <Item quantity="4">QD123</Item>      <Item quantity="5">AC345</Item>  </Invoice>  If the context node is the Invoice element node, the location path child::Item or,  in abbreviated syntax Item will return a node-set containing both Item element nodes. To select both the Date element node and Item element node,you can write the following:  child::*  Or, in abbreviated syntax, use the following:  *  The * indicates any name, and the only nodes in the child axis that have names are element nodes.  To select all child nodes, including comment nodes, processing instruction nodes, and text nodes:  child::node()  Or, in abbreviated syntax, use the following:  node()  If you want to select text node children of a context node, you can write the following:  child::text()  Or, in abbreviated syntax, use the following:  text()