使用Dom4j解析xml文件---DomReader方式

public class Dom4jDomReader {
	
	public static void main(String[] args) {
		
		DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
		DocumentBuilder builder = null;

		try {
			builder = factory.newDocumentBuilder();
			Document document = builder.parse(new File("hello.xml"));
			
			DOMReader reader = new DOMReader();
			
			//JAXP的document转换为dom4j的document对象
			org.dom4j.Document doc = reader.read(document);	
			
			System.out.println(doc.getRootElement().getName());
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

你可能感兴趣的:(使用Dom4j解析xml文件---DomReader方式)