Hi check out below XML
<fish>
<fish1>
<name> f1 </name>
</fish1>
<fish2>
<name> f2 </name>
</fish2>
<fish3>
<name> f3 </name>
</fish3>
</fish>
and you want to select this fish1 and fish3 then use belwo xpath /fish/*[contains('fish1fish3',name())] this will give you NodeList which will contain fish1 and fish3 nodes if your filter includes number of nodes so that writing each name is inefficient then you should use another approach.