Filtering with predicates
With the help of XPath expressions, each requested node can be selected within a XML document. In order to be able to define result sets of nodes and with that to be able to handle more complex tasks, XPath offers the possibility to filter these again by means of predicates. Predicates are attributes which further restrict or filter a node set by returning a Bolean value (true or false). If a node from the node set fulfils the criterion of the predicate, it remains in the result node set. If the node does not fulfil the criterion, it will be filtered from the result node set.
As shown in the indication of the XPath expression, the square bracket is syntactically used which also serves as a guard in the UML notation. Also in XPath, the guard only permits a selection of nodes if the Boolean expression in this bracket is true.
In this example, the expression selects all "POLITICS" element nodes within the document. By using a predicate, the result node set is restricted in a second step: elements which do not meet the condition that the "DEAN" child element has the value "Ott" are filtered out.
<< back | next >> |