Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
788 views
in Technique[技术] by (71.8m points)

having a hardtime to use xmllint to search info in my xml file

I am hoping if anyone can help me on searching "password" info from my xml file using xmllint command. here is my xml file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<server xmlns="urn:jboss:domain:1.4">
    <extensions>
        <extension module="org.jboss.as.clustering.infinispan"/>
        <extension module="org.jboss.as.configadmin"/>
        <extension module="org.jboss.as.connector"/>
        <extension module="org.jboss.as.weld"/>
    </extensions>
    <profile>
        <subsystem xmlns="urn:jboss:domain:logging:1.2">
            <size-rotating-file-handler name="FILE">
                <formatter>
                    <pattern-formatter pattern="%d %-5p [%c] (%t) %s%E%n"/>
                </formatter>
            </size-rotating-file-handler>
        </subsystem>
        <subsystem default-virtual-server="default-host" native="false" xmlns="urn:jboss:domain:web:1.4">
            <connector enable-lookups="false" name="https"
                protocol="HTTP/1.1" scheme="https" secure="true" socket-binding="https">
                <ssl
                    certificate-key-file="${jboss.server.config.dir}/apollo.keystore"
                    cipher-suite="TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_256_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384"
                    key-alias="${apollo.keystore.alias:apollokey}"
                    keystore-type="PKCS12" name="ssl"
                    password="Here is what I want to search"
                    protocol="TLSv1.2" verify-client="false"/>
            </connector>
            <virtual-server enable-welcome-root="false" name="default-host">
                <alias name="localhost"/>
                <alias name="example.com"/>
            </virtual-server>
        </subsystem>
    </profile>
</server>

I am hoping if anyone can help me out to parse this kind of xml file. thanks


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You don't show what xmllint command you're using so it's hard to say exactly what you're doing wrong, but my guess is that you're not accounting for the default namespace.

See this answer for a couple of ways to handle namespaces in xmllint: https://stackoverflow.com/a/8266075/317052

Here's another option that doesn't require you to know the namespace uri...

xmllint --xpath "string(//*[@password]/@password)" input.xml

This will output:

Here is what I want to search

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...