I'm trying to build a Document with Nodes cloned from another
Document. I tried creating a DocumentImpl and asking it to adopt
Nodes:
((DocumentImpl) this._doc).adoptNode(n);
Xerces 1.4.0 complains:
Exception in thread "main" java.lang.ClassCastException:
org.apache.xerces.dom.DocumentImpl
at
org.apache.xerces.dom.AttrImpl.synchronizeChildren(AttrImpl.java, Compiled
Code)
at
org.apache.xerces.dom.DeferredAttrNSImpl.synchronizeChildren(DeferredAttrNSImpl.java,
Compiled Code)
at org.apache.xerces.dom.AttrImpl.setOwnerDocument(AttrImpl.java,
Compiled Code)
at
org.apache.xerces.dom.NamedNodeMapImpl.setOwnerDocument(NamedNodeMapImpl.java,
Compiled Code)
at
org.apache.xerces.dom.ElementImpl.setOwnerDocument(ElementImpl.java,
Compiled Code)
at org.apache.xerces.dom.DocumentImpl.adoptNode(DocumentImpl.java,
Compiled Code)
[... my code]
I took a look at AttrImpl.synchronizeChildren:
protected final void synchronizeChildren(int nodeIndex) {
// we don't want to generate any event for this so turn them off
DeferredDocumentImpl ownerDocument =
(DeferredDocumentImpl) ownerDocument();
[etc]
Ah, it expects to get a DeferredDocumentImpl. I tried making this._doc
be a DeferredDocumentImpl:
this._doc = new DeferredDocumentImpl(new StringPool());
Now I get the error:
Exception in thread "main" java.lang.NullPointerException
at
org.apache.xerces.dom.DeferredDocumentImpl.clearChunkIndex(DeferredDocumentImpl.java,
Compiled Code)
at
org.apache.xerces.dom.DeferredDocumentImpl.getNodeType(DeferredDocumentImpl.java,
Compiled Code)
at
org.apache.xerces.dom.DeferredDocumentImpl.getNodeType(DeferredDocumentImpl.java,
Compiled Code)
at
org.apache.xerces.dom.DeferredDocumentImpl.synchronizeChildren(DeferredDocumentImpl.java,
Compiled Code)
at
org.apache.xerces.dom.DocumentImpl.getDoctype(DocumentImpl.java, Compiled
Code)
at
org.apache.xerces.dom.ElementImpl.getDefaultAttributes(ElementImpl.java,
Compiled Code)
at
org.apache.xerces.dom.ElementImpl.reconcileDefaultAttributes(ElementImpl.java,
Compiled Code)
at org.apache.xerces.dom.DocumentImpl.adoptNode(DocumentImpl.java,
Compiled Code)
I presume that DeferredDocumentImpl does some initialization when a
document is parsed, and this initialization doesn't happen when I just
create an empty one and populate it myself.
Have I discovered a bug, or am I approaching this sitation wrong? I
should be able to adopt a Node to an empty Document, right? I can
imagine situations in which the Document might refuse to accept the
new node as a child, but it should always be willing to adopt it,
right?
Jessica
---
"Users complain that they receive too much spam, while spammers protest
messages are legal." -InfoWorld
"You do not have to do everything disagreeable that you have a right to
do." -Judith Martin (Miss Manners)
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]