Trying to select an element based on the value of one of it's childrens childrens
试着根据其中一个孩子的孩子的价值来选择一个元素。
Thinking the following but not working, appreciate any help, thanks
思考以下问题,但不工作,感谢任何帮助,谢谢
./book[/author/name = 'John']
or
。/ book[/作者/ name = '约翰']
./book[/author/name text() = 'John']
Want all books where the author name = 'John'
想要所有作者名字= 'John'的书
Xml file
Xml文件
<list>
<book>
<author>
<name>John</name>
<number>4324234</number>
</author>
<title>New Book</title>
<isbn>dsdaassda</isbn>
</book>
<book>...</book>
<book>...</book>
</list>
1 个解决方案
#1
233
Almost there. In your predicate, you want a relative path, so change
差不多了。在谓词中,您需要一个相对路径,因此更改
./book[/author/name = 'John']
to either
要么
./book[author/name = 'John']
or
或
./book[./author/name = 'John']
and you will match your element. Your current predicate goes back to the root of the document to look for an author
.
你会匹配你的元素。当前谓词返回到文档的根,以查找作者。
#1
233
Almost there. In your predicate, you want a relative path, so change
差不多了。在谓词中,您需要一个相对路径,因此更改
./book[/author/name = 'John']
to either
要么
./book[author/name = 'John']
or
或
./book[./author/name = 'John']
and you will match your element. Your current predicate goes back to the root of the document to look for an author
.
你会匹配你的元素。当前谓词返回到文档的根,以查找作者。