Blue
Blue

Reputation: 11

How to read array from XML using xmllint

I have below xml, where I need to get values "TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"

    <Configure id="Server" class="org.eclipse.jetty.server.Server">
        <Array id="includedCipherSuites" type="java.lang.String">
            <Item>TLS_AES_128_GCM_SHA256</Item>
            <Item>TLS_AES_256_GCM_SHA384</Item>
            <Item>TLS_DHE_RSA_WITH_AES_256_GCM_SHA384</Item>
        </Array>
    
        <Array  id= "includedProtocols" type="java.lang.String">
            <Item>TLSv1.2</Item>
            <Item>TLSv1.3</Item>
        </Array> 
   </Configure>

I tried, below.

$xmllint --xpath '//Configure/Array/@id' jetty.xml id="includedCipherSuites" id="includedProtocols"

xmllint --xpath '//Configure/Array[0]/@id' jetty.xml XPath set is empty

xmllint --xpath '//Configure/Array[2]/@id' jetty.xml id="includedProtocols"

I am not sure how to read Item from the array with id=includedCipherSuites

Upvotes: 0

Views: 137

Answers (1)

pmf
pmf

Reputation: 36033

Indices are 1-based. So, use Array[1] to address the right array item, then continue traversing down. text() will give you the element contents.

xmllint --xpath '//Configure/Array[1]/Item/text()' jetty.xml

Or use Array[@id="includedCipherSuites"] to select by attribute value:

xmllint --xpath '//Configure/Array[@id="includedCipherSuites"]/Item/text()' jetty.xml

Output:

TLS_AES_128_GCM_SHA256
TLS_AES_256_GCM_SHA384
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384

Upvotes: 2

Related Questions