The XPath specification basically follows the same rule as the file system addressing:
- If the XPath expression starts with a slash (/), it indicates the absolute path of the XML Element (starting from the root of the XML document ).
- If the XPath expression starts with a double slash (//), all elements in the current document that meet the specified conditions are selected, regardless of their position in the XML document. For example,
// Employee
Searches for all employee nodes in the XML document.
- The asterisk (*) selects all XML elements located in the preceding path. For example,
/Company/department /*
Select All subnodes of a department, that is, all employees of the Department.
- Click (.) to select the current node, and click (.) to select the parent node. For example, the XPath expression used to select the department where an employee is located is
../Employee
.
- To select attributes, use
@
Character. For example,/Company/department/employee [@ retired]
SelectedRetired
All employees of the attribute.