XPath Tutorial



XPath Axes


An XPath expression can select the nodes relative to the current node.



AxisDescriptionExample
ancestorAll ancestor nodes of the current node/table/tbody/tr/td/ancestor::tr
ancestor-or-selfthe current node and it's ancestors//tr/ancestor-or-self::tr
attributethe attributes of the current node/item[attribute::price = '100']
childthe children of the current node/item/child::*
descendantthe descendants of the current node/item/descendant::*
descendant-or-selfthe descendants and the current node/item/descendant-or-self::*
followingall the nodes that exist after the current node, not necessarily a sibling/item[@id = '123']/following::*
following-sibling the siblings of the current node sharing the same parent and the same level./item[@id = '123']/following-sibling::*
namespace the namespace of the current node /*/namespace::*
parentthe parent of the current node/item/meta/parent::*
precedingall the nodes that exist before the current node, not necessarily a sibling/item[@id = '123']/preceding::*
preceding-siblingthe siblings of the current node sharing the same parent and the same level./item[@id = '123']/preceding-sibling::*
self the current node /item[@id = '123']/self::item