This topic explains how to search in a DOM tree using an XPath expression.
XPath is a simple query language for XML. An XPath expression describes a subset of an XML tree, such as all the elements with a specified name, or all the children of a specific node. Evaluating an XPath expression means searching in the XML tree for matching nodes or content: clients of the XML Engine use it to explore XML data.
The following steps show how to make an XPath query with the XML Engine.
Before you start, you must:
understand XPath syntax and the concept of Document Object Model (DOM).
understand the architecture and classes of the XML Engine component.
have created an RXmlEngDocument (called myDoc
in this
example), either by parsing an XML file (as indicated in the XML
DOM Parsing Tutorial) or by adding nodes to a new DOM tree.
Create an instance of RXmlEngXPathExpression by calling the TXmlEngXpathEvaluator::CreateExpressionL() method.
Example:
RXmlEngXPathExpression expr = TXmlEngXpathEvaluator::CreateExpressionL( "@*" );
Example:
RXmlEngXPathResult searchResult = expr.EvaluateL( myDoc );
searchResult
variable contains a tree of TXmlEngAttr objects. This tree is a subset of the DOM
tree.
Example:
RXMLEngNodeSet set = result.AsNodeSet(); if( for TInt i = 0; i < set.Length(); i++ ) { TXmlEngNode resultNode = set[i]; /* [...] do something with the result */ }