I found a similar question about SO , however, it seems not quite what I want to achieve:
Let's say this is an example of an XML file:
<root>
<item>
<id isInStock="true">10001</id>
<category>Loose Balloon</category>
</item>
<item>
<id isInStock="true">10001</id>
<category>Bouquet Balloon</category>
</item>
<item>
<id isInStock="true">10001</id>
<category>Loose Balloon</category>
</item>
</root>
If I want to get a “filtered” subset of element elements from this XML, how can I use an XPath expression to access this directly?
XPathExpression expr = xpath.compile("/root/item/category/text()");
Now I know that this will evaluate as a collection of the entire TextContent from the categories, however this means that I have to use the collection to store the values and then iterate and then go back to capture other related information, such as the Item ID again.
Another question: how can I access the parent node correctly?
, xpath , ? , , :
XPathExpression expr = xpath.compile("/root/item/id[@isInStock='true']");
, "" , , ...
? w3cschools ...
, XPath Java, .