🗒️
notes
  • Journal
  • URLs
  • Java Card
    • SCP02
    • Rapid Notes
    • _FIXVALS_
    • Mifare
    • Chain Of Trust
  • Encoding
    • CBEFF
    • Bytes
  • Snippets
    • JNI_OnLoad
  • float to byte[]
  • Protobuf
  • C/C++
    • Containers
    • Basics
    • JNI
    • gcov
    • Castings
  • chess
    • Untitled
  • Compression
    • Untitled
  • Snippets
    • Untitled
  • Build Systems
    • Maven
    • Windows
  • Gradle
  • CMake
  • Java
    • Untitled
    • Certificates
  • Android
    • Mifare
  • Python
    • ctypes
  • WebSub
    • References
  • Spring Boot
    • Form-based Authentication
    • Basic Access Authentication
    • JWT Authentication
  • QR Code
    • Denso QR Code
  • Philosophical Inquiry
    • First
  • XML
    • xmlstarlet
Powered by GitBook
On this page

Was this helpful?

  1. XML

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

PreviousFirst

Last updated 4 years ago

Was this helpful?