Search code examples
xmlxidel

Using Xidel how to extract value from xml file


In the following XML file, I would like to extract the value 300.

<Cube>
    <Cube time="Test">
        <data name="value">300</data>
    </Cube>
</Cube>

I tried the following code but it doesn't seem to be working.

xidel 1.xml -e "css('Cube[time=Test] data[name=value]')/@value"

How would I extract the value?


Solution

  • You don't need the trailing /@value, omit it and your command should return the value 300 fine :

    xidel 1.xml -e "css('Cube[time=Test] data[name=value]')"
    

    or using equivalent XPath expression :

    xidel 1.xml -e "/Cube/Cube[@time='Test']/data[@name='value']"