org.w3c.dom.Document和dom4j的相互转换

/**
* 实现dom4j向org.w3c.dom.Document的转换
* @param doc
* @return
* @throws Exception
*/
public static org.w3c.dom.Document parse(Document doc) throws Exception {
if (doc == null) {
return (null);
}
java.io.StringReader reader = new java.io.StringReader(doc.toString());
org.xml.sax.InputSource source = new org.xml.sax.InputSource(reader);
javax.xml.parsers.DocumentBuilderFactory documentBuilderFactory = javax.xml.parsers.DocumentBuilderFactory
.newInstance();
javax.xml.parsers.DocumentBuilder documentBuilder = documentBuilderFactory
.newDocumentBuilder();
return (documentBuilder.parse(source));
}

/**
*
* 实现 org.w3c.dom.Document到dom4j的转换
* @param doc
* @return
* @throws Exception
*/
public static Document parse(org.w3c.dom.Document doc) throws Exception {
if (doc == null) {
return (null);
}
org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader();
return (xmlReader.read(doc));
}

你可能感兴趣的:(document)