<result>
           <a>login</a>
           <b>1</b>
           <c>1</c>
           <d>00000627</d>
           <e>1</e>
      <userinfo>
           <f>00000627</f>
           <g>852369</g>
           <h>954685</h> 
           <i>公司</i>
      </userinfo>
      <messages>
           <j>登陆成功!</j>
     </messages>
</result>
想要获取节点c和g的值,改如何编写?

解决方案 »

  1.   

    1、导入jdom.jar包
    2、代码import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.input.SAXBuilder;public class JDOMTest
    {
    public static void main(String[] args) throws Exception
    {
    Document document = new SAXBuilder().build("xml.xml");
    Element rootEle = document.getRootElement();
    String cEle = rootEle.getChildText("c");
    String gEle = rootEle.getChild("userinfo").getChildText("g");
    }
    }