XPath Expressions
Following are some of the expressions that you can use to select one or more nodes from the XML document above:
/userinfo
- Selects the root element./userinfo/username
- Selects theusername
node which is the child ofuserinfo
root node.//email
- Selects all the nodes in the document which match the name (email) irrespective of where they lie in the document.//username[@admin]
- Selects all nodes with the name of "username" which have an attribute; "admin"./userinfo/username[1]
- Selects the firstusername
node that is the child ofuserinfo
node./userinfo/username[last()]
- Assuminguserinfo
had more than oneusername
child nodes, it will return the lastusername
node that is the child ofuserinfo
node.
相关文章: