From: "Soumanjoy Das" <[EMAIL PROTECTED]>
> 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).

Thats because the W3C DOM API (which Microsoft implement as well) is a
language neutral API. So the W3C DOM API is pretty similar on Java and .NET
and other languages.


> 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)

The org.dom4j.dom package implements a 'dual tree' that both implements the
dom4j API as well as the W3C API. There could be a bug in there somewhere.
I'll investigate further....

James


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

Reply via email to