使用Java拉取xml值

时间:2014-05-12 18:17:30

标签: java xml href pull

我正在尝试使用JAVA将版本值(2.100.2)拉到href =“someclient.jar”。任何建议?我已经将xml文件解析为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>

爪哇:

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

1 个答案:

答案 0 :(得分:3)

使用XPath

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