1

What XPath expression is needed to use xml starlet select command to get all the XML nodes in the file with name X?

EDIT:

Using this xml

<Parent>
    <Children>

        <Child>
            <Size width="100" height="100"/>
        </Child>

        <Child>
            <Size width="200" height="200"/>
        </Child>

    </Children>
</Parent>

When I run this command nothing is output to the console. I am running version 1.6.1

C:[path_to_xml]>xml sel -t -v "//Size" test.xml

C:[path_to_xml]>

Scorb
  • 1,654
  • 13
  • 70
  • 144
  • In http://stackoverflow.com/questions/15077462/xpath-to-select-all-elements-with-a-specified-name it is implied that `node.SelectNodes("//X");` would work but I don't know how to feed something like that to startlet. – Jerry Jeremiah Dec 09 '16 at 00:28

1 Answers1

0

This xmlstarlet command,

xmlstarlet sel -t -m "//Size" -v "@width" test.xml

will select all Size elements in test.xml and return their width attributes.

Note that earlier versions of xmlstarlet (eg v1.0.1) had issues with returning multiple values. See xmlstarlet XPath expression selects single result rather than multiple.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • That just outputs like 20 blank lines to the console on my windows system. – Scorb Dec 09 '16 at 14:43
  • Add a [mcve] to your question that includes a minimal XML file and the version of xmlstarlet you're using. Thanks. – kjhughes Dec 09 '16 at 14:45
  • @Scorb: I just noticed that you updated your question to show the issue you mentioned in your follow-up comment. I believe it's fixed now. Sorry for the four-year delay. :-) – kjhughes Feb 17 '21 at 15:38