
Select a node by its name: nodename. Example: if the node is an h3 element, the selector is: h3.
Select all the nodes that have a certain attribute: nodename<@attribute>. Example: Select all h3 elements that have a class: //h3<@class>.
Select all the nodes for which a specified attribute has a specified value. Example: Select all h3 elements that have a class having the 'aClass' value: //h3<@class 'aClass'="'aClass'">.
Select the nth child element of a node, having a certain element type: //node/child. Example: Select the third 'li' child of a 'ul' element: //ul/li<3>.
Selecting the parent of a node: .. . Example: parent of a div element that has the class 'aClass': //div<@clas 'aClass'="'aClass'">/.. Let's exemplify some of these selections on a piece of HTML code:
<div class="firstClass">
<li>
<div class="secondClass andThirdClass" >
<h3>
<a href="aRandomLink”> randomText</a>
</h3>
<div class="fourthClass">
<div>
<div class="fifthClass">
<a class="someSpecialClass" href="#" id="firstId">
<span>Some text here</span>
</a>
</div>
<span>Yet more text</span>
</div>
</div>
</div>
</li>
<li>...same structure as the first li...</li><li>...same structure as the previous two lis</li>
</div>
To select:
the h3 element: //h3
the a element whose class attribute is someSpecialClass: //a<@class 'someSpecialClass'="'someSpecialClass'">
the span element that has 'Some text here' as label: //div<@class 'fifthClass'="'fifthClass'">
the span element that has 'Yet more text' as label: //div<@class 'fourthClass'="'fourthClass'">/div/span
the first li element of the first div: //div<@class 'firstClass'="'firstClass'">/li
the second li element of the first div: //div<@class 'firstClass'="'firstClass'">/li<2>
all div elements whose class attributes contain the string 'Class': //div
all div elements that have a class attribute containing the 'second' string and also a class attribute containing the 'Third' string: //div[contains(@class, 'second') and contains(@class, 'Third')