To convert from dom4j nodes to W3C DOM nodes you can use the DOMReader and
DOMWriter classes.

Out of the box a dom4j Node is not a W3C DOM Node. Though if you want a
dom4j node to also implement the W3C DOM API then you can use the
org.dom4j.dom.DOMDocumentFactory which creates a dom4j implementation which
does implement the W3C DOM API.

DocumentFactory factory = new org.dom4j.dom.DOMDocumentFactory();

DOMReader reader = new DOMReader();
reader.setDocumentFactory(factory);
...

or

SAXReader reader = new SAXReader();
reader.setDocumentFactory(factory);

James
----- Original Message -----
From: "Bram Huenaerts" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, July 11, 2002 3:37 PM
Subject: [dom4j-user] Casting problem between org.w3c.dom.Node &
org.dom4j.Node


> Dear readers & problemsolvers,
>
> while programming i had the next error:
>
> <ERROR>
> Cannot convert: org.dom4j.tree.DefaultElement@9fd93 [Element: <book att
> ributes: []/>] into a W3C DOM Node
> Exception in thread "main" org.w3c.dom.DOMException: Not supported yet
>         at
org.dom4j.dom.DOMNodeHelper.notSupported(DOMNodeHelper.java:429)
>         at org.dom4j.dom.DOMNodeHelper.asDOMNode(DOMNodeHelper.java:366)
>         at dom4jTest.main(dom4jTest.java:84)
> </ERROR>
>
> The problem is that i can't cast a dom4j.Node to a w3cNode!
>
> <CODE>
> import org.dom4j.*;
> ....
> // parse a document into a DOMDocument.
> org.w3c.dom.Document domDocument = builder.parse(new
> File("record.xml"));
> DOMReader reader = new DOMReader();
>
> // Convert the DOMDocument to a DOM4J-Document
> Document dom4JDocument = reader.read(domDocument);
>
> // Casting the Object
> Node dom4jBookNode =
> xpathSelector.selectSingleNode(dom4jDocument);
> org.w3c.dom.Node BookNode =
> DOMNodeHelper.asDOMNode(dom4jBookNode);
>
> domDocument = (org.w3c.dom.Document) dom4jDocument;
> ...
> </CODE>
>
> None of the conversions are working.
> When i use DOMWriter i can get a valid W3C Document.
> The problem is I should be able to convert the Nodes!
> Any help is welcome...
>
> Regards
> --
> Huenaerts Bram
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> PC Mods, Computing goodies, cases & more
> http://thinkgeek.com/sf
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user
>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.comm


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to