Reputation: 355
I read a number of xmllint answers about similar issue, but none seemed applicable to my specific case (maybe I missed it). Anyway, I have a following XML:
<?xml version="1.0"?>
<items>
<item>
<name>Name 1</name>
<value>3</value>
</item>
<item>
<name>Name 2</name>
<value>4</value>
<othervalue>5</othervalue>
</item>
</items>
I want to select "value" from "item" of a specific name, but when I enter
xmllint --xpath '//items/item[@name="Name 1"]' test.xml
I get:
XPath set is empty
-:1: parser error : Document is empty
I suspect because "name" is not a property inside the "item" tag, but I'm not sure how deal with that, is there a way to iterate through items and check each one for name (using a bash script perhaps)?
Upvotes: 2
Views: 1184
Reputation: 52858
name
isn't an attribute so it shouldn't be prefixed with @
(which is abbreviated syntax for attribute::
).
Try:
/items/item[name="Name 1"]/value
Upvotes: 2