« Do You Know About T4 (Text Template Transformation Toolkit) Code Generation In Visual Studio? | An inspiring concept video of what next-generation UX could be and what digital life might be »
XPath expressions quick reference:
by Vahid 7. May 2009 07:00
if you work with XML and xpath for sure the reference seems to be a trivial one for you. but if you stop working with xml and xpath for a while you’ll find the reference pretty handy. i personally keep it with me always. hope it also helps you.
the reference xpath expression is for this xml content:
1: <?xml version="1.0" encoding="utf-8" ?>
2: <Albums>
3: <Album country="USA">
4: <title>Empire Burlesque</title>
5: <artist>Bob Dylan</artist>
6: <price>10.90</price>
7: </Album>
8: <Album country="UK">
9: <title>Hide your heart</title>
10: <artist>Bonnie Tyler</artist>
11: <price>10.0</price>
12: </Album>
13: <Album country="USA">
14: <title>Greatest Hits</title>
15: <artist>Dolly Parton</artist>
16: <price>9.90</price>
17: </Album>
18: </Albums>
and here is the quick reference
| /Albums | selects the root element |
| /Albums/Album | selects all the Album elements of the Albums element |
| /Albums/Album/price | selects all the price elements of all the Album elements of the Albums element |
| /Albums/Album[price>10.0] | selects all the Album elements with price greater than 10.0 |
| starts with a slash(/) | represents an absolute path to an element |
| starts with two slashes(//) | selects all elements that satisfy the criteria |
| //Album | selects all Album elements in the document |
| /Albums/Album/title | /Albums/Album/artist |
| //title | //artist |
| /Albums/Album/* | selects all the child elements of all Album elements of the Albums element |
| /Albums/*/price | selects all the price elements that are grandchildren of Albums |
| /*/*/price | selects all price elements which have two ancestors |
| //* | selects all elements in the document |
| /Albums/Album[1] | selects the first Album child of Albums |
| /Albums/Album[last()] | selects the last Album child of Albums |
| /Albums/Album[price] | selects all the Album elements that have price |
| /Albums/Album[price=10.90] | selects Album elements with the price of 10.90 |
| /Albums/Album[price=10.90]/price | selects all price elements with the price of 10.90 |
| //@country | selects all “country” attributes |
| //Album[@country] | selects Album elements which have a “country” attribute |
| //Album[@*] | selects Album elements which have any attribute |
| //Album[@country=‘UK’] | selects Album elements with “country” attribute equal to ‘UK’ |
Related posts
XML Tools Normal 0 false false false EN-US X-NONE AR-SA Micr…Software development security check list Recentely i have joined a new as a technical architect. the very thing after getting to the domain…Some cool .Net open source applicaitons i have worked with some cool open source applications which are based on microsoft .net framework …
Powered by BlogEngine.NET 1.6.0.0
Theme by Mads Kristensen