<?xml version="1.0" encoding="GB2312"?>
<req>
<type>03</type>
<mailname>[email protected]</mailname>
<passwd>123456</passwd>
<sessionid>kkkkkkk</sessionid>
<getmail>1</getmail>
<mailid status="R">23423</mailid>
<mailid status="R">23424</mailid>
<mailid status="D">23425</mailid>
</req>

解决方案 »

  1.   


    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(f);
      

  2.   


    try {
    SAXBuilder builder = new SAXBuilder();

    Document document = builder.build( new File("pool.xml") );


    Element element = document.getRootElement();

    System.out.println( element.getName() );

    List list = element.getChildren("pool");
    for(int i=0;i<list.size();i++){
    Element child = (Element) list.get( i );
    System.out.println( child.getName() );

    List list2 = child.getChildren();
    for(int j=0;j<list2.size();j++){
    Element child2 = (Element) list2.get( j );
    System.out.println( "   "+ child2.getName() + "              = " + child2.getValue() );

    }

    }
    } catch (JDOMException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
      

  3.   

    我觉得还是dom4j最好用 ,推荐一下