Simplest way to query XML in Java

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

I have small Strings with XML, like:

String myxml = \"goodhi\";
<
9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 06:43

    convert this string into a DOM object and visit the nodes:

    Document dom= DocumentBuilderFactory().newDocumentBuilder().parse(new InputSource(new StringReader(myxml)));
    Element root= dom.getDocumentElement();
    for(Node n=root.getFirstChild();n!=null;n=n.getNextSibling())
     {
     System.err.prinlnt("Current node is:"+n);
     }
    

提交回复
热议问题