Converting org.w3c.dom.Document into org.dom4j.Document
807588Jul 1 2009 — edited Jul 1 2009Can somebody help me with a code segment describing, how to convert a org.w3c.dom.Document in to org.dom4j.Document .
I already tried the following, but it gives an exception --
Exception : org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
I am using the folowing method and pasing an org.w3c.dom.Element in the params --
public org.dom4j.Element convert( org.w3c.dom.Element element) throws ParserConfigurationException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc1 = builder.newDocument();
doc1.appendChild( element);
// Convert w3c document to dom4j document
org.dom4j.io.DOMReader reader = new org.dom4j.io.DOMReader();
org.dom4j.Document doc2 = reader.read( doc1);
return doc2.getRootElement();
}
Can anybody help me on this issue.
Thanks
Cynthia