Hi James,

I'm sorry if this is due to something that I'm doing wrong. I downloaded the
daily build from www.dom4j.org, and extracted dom4j-full.jar, dom4j.jar,
jaxen.jar, xerces.jar, saxon.jar. But the same piece of code (as before) now
gives a different error at runtime, at a different line:

import org.w3c.dom.*;
import org.dom4j.dom.*;
//import etc...

    DOMDocument oDocument = new DOMDocument("Root");
        //Add two node elements with attributes "name" and "id"
    Element oParent = oDocument.createElement("Parent"); //<--This now works
fine (used to throw an error earlier)
    oParent.setAttribute("name", "N01");
    oParent.setAttribute("id", "ID01");

    oDocument.appendChild(oParent); //<-- Fails here, Error message is below

    oParent = oDocument.createElement("Parent");
    oParent.setAttribute("name", "N02");
    oParent.setAttribute("id", "ID02");
    oDocument.appendChild(oParent);
    oParent = oDocument.createElement("Parent");
    Element oSearch = (Element)oDocument.selectSingleNode("//Parent[@name =
'N01']");
    System.out.println(oSearch.getAttribute("id"));

This is the error message that occurs at runtime (no compilation errors):

org.w3c.dom.DOMException: Children not allowed for this node:
org.dom4j.dom.DOMDocument@480457 [Document: name Root]
        at org.dom4j.dom.DOMNodeHelper.appendChild(DOMNodeHelper.java:152)
        at org.dom4j.dom.DOMDocument.appendChild(DOMDocument.java:162)
        at com.interrait.requesttracker.Dump.main(Dump.java:74)
Exception in thread "main"

Is there some incompatibility between org.w3c.dom and org.dom4j.dom Classes
that I'm missing? I've read the documentation and made sure of the
derivations, inheritances and implementations, and according to those, there
should be no errors. However, perhaps you could throw more light on it. If
this code DOES work fine at your end, could you send me the exact code
(starting from the imports right up to the end of the class) so that I may
find out what I'm doing wrong? Thanks for your help. :-)

Regards
Soumanjoy

-----Original Message-----
From: James Strachan [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 19, 2002 11:36 PM
To: Soumanjoy Das; [EMAIL PROTECTED]
Cc: 'Silvain Piree'
Subject: Re: [dom4j-user] Runtime error in
org.dom4j.dom.DOMDocument.createElement()


Hi Soumanjoy

Sorry this took me a while to get around to fixing. You did indeed find a
bug. I added your test case to dom4j/src/test/org/dom4j/dom/TestDOM.java.

I've applied a patch that fixes it. Its available in CVS and the daily
build. Thanks for spotting this!

James

_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to