XPath

  • A set of rules/languages for finding information in XML files, traversed by XML elements or attributes
  • www.w3school.com.cn/xpath/index…

XPath development tools

  • Open source XPath expression editing tool: XMLQuire
  • Chrome plugin: XPath Helper
  • Firefox plugin: XPath Checker

Select the node

  • Nodename: selects all child nodes of this node

  • /: Starts from the root node

    /Student: no demerits /School: select the School nodeCopy the code
  • //: select node, regardless of position

    //Age: Three nodes are selected and returned as a listCopy the code
  • .: Selects the current node

  • . : Selects the parent node of the current node

  • @: Select an attribute

  • XPath lookup usually follows the path method. Here is the path representation

    School/Teacher: return Teacher node School/Student: return two Student nodes Select all Age nodes in the descendant of School // @other: select the Other attribute //Age[@detail]: select the Age element with the attribute DetailCopy the code
  • Predicate – Predicates

  • /School/Student[1]: select the first Student node below School

  • /School/Student[last()]: selects the last Student node below School

  • /School/Student[last()-1]: select the last Student node below School

  • /School/Student[position() < 3]: select the first two Student nodes below School

  • // score [@score]: selects the score node

  • //Student[@score=”99″]: select score from Student where score is 99

  • //Student[@score]/Age: select the Age of the child of the score node

Some operations on XPath

  • | : or

    / / Student / @ score | / / the Teacher: select nodes with attribute score Student or the TeacherCopy the code
  • Other unusual XPath notations include +, -, *, div, >, <