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方式
最新推荐文章于 2022-05-23 20:04:30 发布