xmllint: Get an item from a list using

Viewed 818

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)?

1 Answers
Related