Download Delve® SOA Fast-Prototyping Toolkit (Beta 1.0)
| Tutorials - How to Apply a Simple XPath Filter |
Page 1 of 2 |
In this lesson, we’ll take a look at how to go about using the simplest of XPath filters, the “presence” filter, which limits a selection to those members possessing a member of a particular name. This is handy when you want to collect a batch of elements from a target document that all have the same name, but different sets of members. If you aren’t yet familiar with XPath and accessors, you might want to check out some of those lessons first.
To apply an XPath filter, you use standard XPath syntax, putting conditions in a set of brackets that follow a target member name. Suppose we have an XML document that represents a set of parents.

To select only those parents with daughters, we can use a filter in accessor statement like this:

Now instead of obtaining all “parent” elements, the accessor statements obtain only those specified in the filter. We’ve populated the filter with the path from “parent” to “daughter,” ensuring that only those elements with a “daughter” element will meet the filter criteria.
|