0

In a linux command line, I need to get all the text values from all the items in this xml (or at least one like it):

<Configuration xmlns="http://path.com/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" description="The initial configuration setup" name="InitialConfig">
<Cluster>
    <Category name="Change Notification" visibility="Advanced">
        <ConfValue description="I am a description" listDefault="" name="Repositories stuff" propname="com.path.repositories" sinceVersion="1.2" visibility="Advanced">
            <ConfList>
            <ConfListString value="val1"/>
            <ConfListString value="val2"/>
            <ConfListString value="val3"/>
            <ConfListString value="etc"/>
            </ConfList>
        </ConfValue>
    </Category>
    <Category name="List of objects for stuff" visibility="Advanced">
        <ConfValue description="I am a description" listDefault="" name="Repositories for notification" propname="com.path.config" sinceVersion="1.2" visibility="Advanced">
            <ConfList>
                <ConfListString value="val4"/>
                <ConfListString value="val5"/>
                <ConfListString value="val6"/>
                <ConfListString value="etc"/>
            </ConfList>
        </ConfValue>
    </Category>
</Cluster>

I need propname and the ConfListString value. command output would hopefully look like this:

com.path.repositories - val1
com.path.repositories - val2
com.path.repositories - val3
com.path.repositories - etc
com.path.config - val4
com.path.config - val5
com.path.config - val6
com.path.config - etc

On the servers I'm working with, "xmllint --xpath" doesn't work because "Unknown option --xpath" a known issue libxml2. And I don't think they will let me upgrade them.

Thanks in advance!

Community
  • 1
  • 1
masonje
  • 49
  • 1
  • 5

1 Answers1

0

I've seen various incarnations of this question. Today I found the simplest solution in xml_grep (which you can easily obtain as xml-twig-tools on Debian and perl-xml-twig on Alpine.)

Take for example what appears to be the canonical use case; getting the version from a maven pom file:

xml_grep --text_only '/project/version' pom.xml

The benefit of this tool is that it simply seems to ignore XML namespaces which is ideal compared to alternatives.

Ray
  • 1,324
  • 10
  • 18