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
----- Original Message -----
From: "Soumanjoy Das" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "'Silvain Piree'" <[EMAIL PROTECTED]>
Sent: Friday, April 12, 2002 4:48 AM
Subject: [dom4j-user] Runtime error in
org.dom4j.dom.DOMDocument.createElement()


> Hello everyone, (Hi Sylvain),
>
> Being a newcomer to JDOM, I was surprised to see that some classes in
> org.dom4j.dom and org.w3c.dom have exactly similar methods as Microsoft
DOM
> (as in name and semantics). Since it seemed too good to be true (I was
> looking to convert my VB code to Java in the first place), I gave it a
try.
> Thanks to Sylvain, I've learnt a way to use DocumentHelper to do the work
> that I need. But I just tried out the following code out of curiosity.
Could
> anyone please tell me why the code fails at the line indicated?
>
> import org.w3c.dom.*;
> import org.dom4j.dom.*;
>
> DOMDocument oDocument = new DOMDocument("Root");
> //Add two subnodes with attributes "name" and "id"
> Element oParent = oDocument.createElement("Parent"); //<-- Fails here,
Error
> message is below
> oParent.setAttribute("name", "N01");
> oParent.setAttribute("id", "ID01");
> oDocument.appendChild(oParent);
> oParent = oDocument.createElement("Parent");
> oParent.setAttribute("name", "N02");
> oParent.setAttribute("id", "ID02");
> oDocument.appendChild(oParent);
>
> Element oSearch = (Element)oDocument.selectSingleNode("//Parent[@name =
> 'N01']");
> System.out.println(oSearch.getAttribute("id"));
>
> It compiles fine, but gives an error at runtime:
>
> java.lang.ClassCastException: org.dom4j.tree.DefaultElement
> at org.dom4j.dom.DOMDocument.createElement(DOMDocument.java:209)
> at com.interrait.requesttracker.Dump.main(Dump.java:70)
> Exception in thread "main"
>
> Anything wrong with the code? I'd appreciate any suggestions.
>
> Thanks
> Soumanjoy
>
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


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

Reply via email to