What XPath can I use to select any category with a name attribute specified and any child node author with the value specified.
I've tried different variations of the path below with no success:
//quotes/category[@name='Sport' and author="James Small"]
The XML:
<?xml version="1.0" encoding="utf-8"?>
<quotes>
<category name="Sport">
<author>James Small<quote date="09/02/1985">Quote One</quote><quote date="11/02/1925">Quote nine</quote></author>
</category>
<category name="Music">
<author>Stephen Swann
<quote date="04/08/1972">Quote eleven</quote></author>
</category>
</quotes>
Use:
or use:
It is a good rule to try to avoid using the
//
pseudo-operator whenever possible, because its evaluation can typically be very slow.Also:
is equivalent to:
so it is recommended to use the latter.
question is not clear, but what i understand you need to select a catagory that has name attribute and should have child author with value specified , correct me if i am worng
here is a xpath
Try:
//category[@name='Sport' and ./author/text()='James Small']