Introduction to xpath
1.xpath uses path expressions to navigate in xml and html
2.xpath contains standard function library
3.xpath is a w3c standard
xpath node relationship
1. Parent node
2. Child node
3. Sibling node
4. Ancestor Node
5. Descendant Nodes
xpath syntax
expression | s description |
article | Select all child nodes of article element |
/article | Select the root element article |
article/a | Selects all elements that belong to the child element a of article |
//div | Selects all div child elements (regardless of where they appear in the document) |
/article//div | Selects all descendant div elements that belong to the article element. no matter where it appears under the article element |
//@class | Select all attributes named class |
/article/div[1] | Select the first div element that is a child of article |
/article/div[last()] | Select the last div element that is a child of article |
/article/div[last()-1] | Selects the penultimate div element that is part of the article child element |
// div [@lang] | Select all div elements that have lang familiarity |
//div[@lang='narrow'] | Select all elements whose lang attribute is eng |
/div/* | Select all child nodes belonging to a div element |
//* | select all elements |
//div[@*] | Select all div elements with attributes |
/div/a|//div/p | Select a and p elements of all div elements |
//span|//ul | Select span and ul elements in the document |
article/div/p|//span | Select all p elements of div elements that belong to the article element, and all span elements in the document |