xmlstarlet

A normative exhaustion of every possible

<root>
    <elem>
        <node n="132">
            <type>face</type>
        </node>
        <desc>hello</desc>
    </elem>
    <node n = '456'>
        <type>face</type>
    </node>
    <desc>bye</desc> 
    <node>
        <type>iris</type>
    </node>   
</root>

Extract element value constraint by sibling condition:

x=$(xml sel -t -v "//elem/node[type='face']/../desc" root.xml)

The above extracts the desc element value if node and desc are siblings and node has a type child node with value face. The parent of the two siblings is elem.

Extract element value constraint by element attribute value

xml sel -t -v "//node[@n='123']/type" root.xml

Extract element value constraint by element attribute presence

xml sel -t -v "//node[not(@n)]/type" root.xml

Extract element value constraint by parent element

Extract element value constraint by parent element attribute

Extract element value constraint by child element

Extract element constraint by its value

Count elements

Count elements having any of the above constraint

Last updated

Was this helpful?