Re: Creating a Document from a Node
On Mon, 28 Jul 2008, pwaring@gmail.com wrote:
On Jul 28, 2:01 pm, Tom Anderson <t...@urchin.earth.li> wrote:
What did the actual class of the Node turn out to be?
Just a Node (i.e. not a subclass) as far as I could tell.
Node is an interface. This probably isn't important, but if you wanted to
see what the implementing class was, you could do
someNode.getClass().getName().
However, this throws an exception with the message: "Error: newChild
cannot be a child of this node". Does anyone know how/if I can get
round this?
Try Document.adoptNode or importNode, according to whether you want to
remove the Node from the original Document or not.
I've tried that, with the following code:
Document content = createEmptyDocument();
Node currentDiv = divs.item(i); // divs is just all the <div> nodes from a document
content.adoptNode(currentDiv);
which results in the following error (at runtime - no problems during
compilation):
java.lang.AbstractMethodError:
org.w3c.tidy.DOMDocumentImpl.adoptNode(Lorg/w3c/dom/Node;)Lorg/w3c/dom/Node;
Well that's not good.
AbstractMethodError usually means there's a library screwup: your code is
fine, but somewhere, there's a class A which thinks class B has an
implementation of some method, while class B declares that method as
abstract. Typically, A and B are in separate JARs, and A was compiled
against a previous version of B, which has since changed to turn a method
from concrete to abstract.
I'd look at Tidy, your XML parser (if any) and any other DOM-related
libraries, and see if (a) the one you think is being loaded really is (by
looking round your classpath etc), (b) they're the versions you think they
are and (c) whether they could or should be more up to date.
tom
--
an optical recording release. copyright digitally mastered. .,