Simplest way to query XML in Java

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

I have small Strings with XML, like:

String myxml = \"goodhi\";
<
9条回答
  •  不知归路
    2020-11-30 06:29

    @The comments of this answer:

    You can create a method to make it look simpler

    String xml = "goodhi";
    
    System.out.printf("satus= %s\n", getValue("/resp/status", xml ) );
    

    The implementation:

    public String getValue( String path, String xml ) { 
        return XPathFactory
                   .newInstance()
                   .newXPath()
                   .evaluate( path , new InputSource(
                                     new StringReader(xml)));
    
    }
    

提交回复
热议问题