dom4j解析xml

/**

 * 

 */

package com.xcj.test.test;

 

import java.io.File;

import java.util.Iterator;

import java.util.List;

 

import org.dom4j.Attribute;

import org.dom4j.Document;

import org.dom4j.Element;

import org.dom4j.io.SAXReader;

 

/**

 * @author xcj

 *

 */

public class festXml {

 

/**

* <b>function:</b> 

* @project xcjedu

* @package com.xcj.test.test  

* @fileName @param args

* @createDate Jun 3, 2014 4:46:48 PM

* @author yy.niu

*/

public static void main(String[] args) {

try{

SAXReader sax = new SAXReader();  

       Document xmlDoc = sax.read(new File("E:\\xcjmanifest.xml"));  

       Element root = xmlDoc.getRootElement();//根节点 

       Attribute identifier = root.attribute("identifier");

       System.out.println(identifier.getText());

       List list = root.selectNodes("//metadata");  

       for(int i=0;i<list.size();i++){

       Element pro = (Element)list.get(i);  

           System.out.println(pro.elementText("schema"));

           System.out.println(pro.elementText("schemaversion")); 

       }

       for(Iterator iter = root.elementIterator(); iter.hasNext();){

       Element element = (Element) iter.next();

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

       }

}catch(Exception e){

e.printStackTrace();

}

 

 

}

 

}

 

你可能感兴趣的:(dom4j)