programming and software tutorials
An XPath quick reference
This is a very brief quick reference for those of you who know what XPath is, but don’t use it often enough to have it ingrained in your heads, like myself.
XPath Examples
| //person | Returns a NodeSet containing ALL XML tags in the document with the name ‘person’, no matter where they are in the document. |
| //person[@firstname='patrick'] | Returns a NodeSet containing ALL XML tags in the document with the name ‘person’ and an attribute ‘firstname’ with a value of ‘patrick’, no matter where they are in the document. |
| /person/@firstname | Returns the value of the attribute ‘firstname’ for all direct children with a name of ‘person’. |
| /animal[contains(string(),'rabbit')] | Returns all ‘animal’ tags that have a string value containing the string ‘rabbit’. |
I highly recommend a site out there that allows you to test your XPath’s right on the site: http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm
| Print article | This entry was posted by Chad Challis on February 14, 2010 at 1:14 am, and is filed under DOM, PHP. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |