Simplest way to query XML in Java

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

I have small Strings with XML, like:

String myxml = \"goodhi\";
<
9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 06:36

    Here is a code snippet of querying your XML with VTD-XML

    import com.ximpleware.*;
    public class simpleQuery {
    
        public static void main(String[] s) throws Exception{
            String myXML="goodhi";
            VTDGen vg = new VTDGen();
            vg.setDoc(myXML.getBytes());
            vg.parse(false);
            VTDNav vn = vg.getNav();
            AutoPilot ap = new AutoPilot(vn);
            ap.selectXPath("/resp/status");
            int i = ap.evalXPath();
            if (i!=-1)
                System.out.println(" result ==>"+vn.toString(i));
        }
    }
    

提交回复
热议问题