I have a NodeList in Java and this XML file, (just a part of it)
if I have
<Book title="aaa" author="bbb" price="12" year="2011" />
I can use an XPath expression to see if some conditions are verified, for example:
local-name(.) = 'Book' and @title local-name(.) = 'Book' and @title
If the result of XPath expression execution is true...do something, otherwise do something else. In this case I built an expression directly on a Node, and that's ok.
In the case of NodeList, how can I do the same task? I would like to see if NodeList (org.w3c.NodeList in Java) has some nodes, for example, but using an XPath expression.
Thanks Luca
您可以遍历NodeList
节点,并将xpath应用于每个节点。
If the node-set is in a variable $v
, then the following XPath expression:
$v[self::Book and @title]
selects all nodes from $v
that are Book
elements and that also have an attribute named title
.
If the node-set can be obtained as the result of evaluation a particular XPath expression, then you can substitute $v
with this expression:
yourExpression[self::Book and @title]
For example, if the node-set in question consists of all nodes returned by /*/*
, then one expression that selects the wanted nodes from this node-set is:
/*/*[self::Book and @title]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.