Title: [REQ] Problem with DocumentHelper.createDocument(Element)

Hello,

I am experiencing some problems with dom4j version 1.1, when I am attempting to create a document using the DocumentHelper.createDocument(Element); method.

This is the code that invokes the createDocument method :
        //==============================================================
        // Convert the CXmlElement to an XML Element
        //==============================================================
        Element objElement = toXML(xmlElement, sessionSB_p);

        //==============================================================
        // Create an empty XML Document, passing its root element
        //==============================================================
        Document xmlDoc = DocumentHelper.createDocument(objElement);

And here is the error returned:
org.dom4j.IllegalAddException:The node "org.dom4j.tree.DefaultElement@3e89c3 [Element: <object attributes:
org.dom4j.tree.DefaultAttribute@4695a6 [Attribute: name name value "root"], org.dom4j.tree.DefaultAttribute@acf6e
[Attribute: name class value "com.kainos.core.CUserPK"]]/>]" could not be added to the branch "null" because: The Node already has an existing document: org.dom4j.tree.DefaultDocument@6a0252 [Document: name null]

I have also tried
1.
Document xmlDoc = DocumentHelper.createDocument();
xmlDoc.setRootElement(objElement);
Which generates the same error.

2.
Document xmlDoc = DocumentHelper.createDocument();
root = xmlDoc.getRootElement();
root.add(objElement);

The objElement contains the following XML
<object name="root" class="com.kainos.core.CUserPK">
  <attributes>
    <object name="Id" class="java.lang.Integer" value="10001"/>
  </attributes>
</object>

Any ideas what could cause this problem?

Regards,
Cedric Picard,
Software Engineer
Kainos Software Ltd.

--

This e-mail is confidential and is intended for the named recipient only. If
you receive it in error please destroy the message and all copies. Kainos
Software Ltd. does not accept liability for damage sustained as a result of
malicious software (e.g. viruses). Kainos does not accept liability for, or
permit, the creation of contracts on its behalf by e-mail, the publication of
any defamatory statement by its employees by e-mail, or changes subsequently
made to the original message. The Company's registered office is located at
4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland, Tel +44 28 9057 1100.

Reply via email to