我可以使用什么 XPath 来选择具有指定名称属性的任何类别以及具有指定值的任何子节点作者。
我尝试了以下路径的不同变体,但没有成功:
//quotes/category[@name='Sport' and author="James Small"]
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>
尝试: //category[@name='Sport' and ./author/text()='James Small']
//category[@name='Sport' and ./author/text()='James Small']