jdoyle0116
jdoyle0116

Reputation: 83

Pulling xml value using Java

I'm trying to pull the version value (2.100.2) where href="someclient.jar" using JAVA. Any suggesstions? I've gotten up to parsing the xml file into a Document.

<?xml version="1.0" encoding="utf-8"?>
    <jnlp>
       <resources>
        <jar href="someclient.jar" version="2.100.2" />
        <jar href="cisco-upgrade.jar" version="1.5" />
        <jar href="collections.jar" version="1.1" />
        <jar href="commons-codec.jar" version="1.4" />
        <jar href="commons-email.jar" version="1.1" />
       </resources>
    </jnlp>

Java:

File fileXML = new File(path);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fileXML);

Upvotes: 0

Views: 40

Answers (1)

Arjit
Arjit

Reputation: 3456

Use XPath

String expression = "/jnlp/resources/jar[@href='someclient.jar']/@version";

Upvotes: 3

Related Questions