XPATH allows the use of wildcards to write more robust path expressions where the use of specific path expressions is either impossible or undesirable.
XPATH supports the following wildcards:
|*||matches any element node.|
|@*||matches any attribute node.|
|node()||matches any type of node.|
The wildcard is used in place of the literal name of a node.
The examples use the library XML document as a reference.
Example: Match All Nodes
- Matches ALL nodes in the input XML document.
Example: Match All Categories
- Matches all child nodes of library – in this example the only child nodes are category.
- Matches all category nodes as children of the root node (library). If there are nodes other than category under the library node then this expression will only return the required category nodes.
Example: Match All Books
- Matches all children under the category node. In our example XML the only children are the book nodes.
- Matches all book nodes located at that level in our XML hierarchy.
Example: Match All Elements With An Attribute
- Matches ANY element node which has an attribute defined. This example will only match category and title nodes.
- Matches only title element nodes with an attribute defined.