...
Filters use XPath expressions to find element nodes that should be excluded from the published XML.
How to write an XPath expression?
All XPath expressions examples from this guide refer to the following XML:
Code Block |
---|
<library>
<books>
<book type=”classic”>
<author>
<firstname>Charles</firstname>
<lastname>Dickens</lastname>
</author>
<title>A Tale of Two Cities</title>
<price currency="EUR">15.99</price>
</book>
<book type=”fantasy”>
<author>
<firstname>George</firstname>
<lastname>Martin</lastname>
<birthdate>20.02.1998</birthdate>
</author>
<title>A Game of Thrones</title>
<price currency="GBP">21.99</price>
</book>
<book type=”science”>
<author>
<firstname>Stephen</firstname>
<lastname>Hawking</lastname>
</author>
<title>Brief Answers to the Big Questions</title>
<price>13.99</price>
</book>
</books>
<manager>
<firstname>John</firstname>
<lastname>Doe</lastname>
</manager>
<owner>
<firstname>Jeff</firstname>
<lastname>Bezos</lastname>
</owner>
</library> |
To better understand this guide, you can use http://xpather.com/ to try XPath expressions on previously shown XML. You can also use this website in the future to validate your Filters, but please do not use any XMLs containing sensitive data.
The simplest and the most efficient way to provide an XPath to an element is to list all elements from the root element to the desired one, separated by a slash(/).
Info |
---|
library/manager/lastname - selects the library owner's first name. |
In case an exact path is unknown or does not include all desired nodes, a double slash(//) or an asterisk(*) can be used.
// - Selects nodes in the document from the current node that match the selection no matter where they are
Info |
---|
//firstname - same as library/books/author/firstname and library/manager/firstname together |
slash(/) and double slash(//) can be combined
Info |
---|
library/books//firstname - selects authors' firstname, but not manager's and owner's |