Simplest way to query XML in Java

后端 未结 9 587
南旧
南旧 2020-11-30 05:55

I have small Strings with XML, like:

String myxml = \"goodhi\";
<
9条回答
  •  长情又很酷
    2020-11-30 06:26

    XPath using Java 1.5 and above, without external dependencies:

    String xml = "goodhi";
    
    XPathFactory xpathFactory = XPathFactory.newInstance();
    XPath xpath = xpathFactory.newXPath();
    
    InputSource source = new InputSource(new StringReader(xml));
    String status = xpath.evaluate("/resp/status", source);
    
    System.out.println("satus=" + status);
    

提交回复
热议问题