Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting org.w3c.dom.Document into org.dom4j.Document

807588Jul 1 2009 — edited Jul 1 2009
Can 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2009
Added on Jul 1 2009
5 comments
2,600 views