Glad to be of service. I do have a few curiosities about your code fragment
below.  I've inserted my questions below...

--------------
Brion Swanson - West Group / Rochester, NY
mailto:[EMAIL PROTECTED]


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 30, 2001 9:18 AM
To: [EMAIL PROTECTED]
Subject: RE: DocumentFragment (bug?)

> Ok, I did not make myself clear, but your answer already told me that I
was
> not using DocumentFragment for the right job.
> 
> Here is what I meant (I haven't compiled that code, but that is the
essence
> of what I am doing)
> <pre>
> javax.xml.parsers.DocumentBuilderFactory dbf=
> javax.xml.parsers.DocumentBuilderFactory.newInstance();
> 
> javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
> 
> org.w3c.dom.Document doc1 = db.newDocument();
> org.w3c.dom.Document doc2 = db.newDocument();
> 
> org.w3c.dom.Node a = doc.createElement("a");
> org.w3c.dom.Node c = doc.createElement("c");
> org.w3c.dom.Node c1 = doc.createElement("c1");
> c.appendChild(c1);
> a.appendChild(b); 

Did I miss the declaration of the 'b' Node?  There's one below, but that's a
Node of a different document (i.e. doc2) and the append won't work without
an import.

> a.appendChild(c);
> 
> org.w3c.dom.Node b = doc2.createElement("b");
> org.w3c.dom.Node b1 = doc2.createElement("b1");
> org.w3c.dom.Node b2 = doc2.createElement("b2");
> org.w3c.dom.Node b3 = doc2.createElement("b3");
> 
> b.appendChild(b1); b.appendChild(b2); b.appendChild(b3);
> 
> org.w3c.dom.DocumentFragment docFrag2 = doc2.createDocumentFragment();
> docFrag.appendChild(b1); docFrag.appendChild(b3);
> 
> org.w3c.dom.DocumentFragment docFrag1 = doc2.importNode(docFrag2, true);

Why do you import a node to the same document in which it was created?
docFrag2 was created by doc2 and here you're calling doc2.importNode on that
same Node and calling the result docFrag1 (which is really still a doc2
Node).  Was this just a typo?

> c.replaceChild(docFrag1, c1);

Naturally, because of the previous import, this statement should not work as
Node 'c' is part of doc1 and docFrag1 is still part of doc2.

> </pre>
> 
> I expected docFrag2 to still contain b1i and b3i (the imported versions of
b1 and b3)  After all the references are still valid.
> 
> But, for the purpose of this mail I have debugged this piece of code and
realised
> that adding nodes to the DocumentFragment actually makes it their owner
node, which I didn't know.
> I should have know, after all the spec says that a DocumentFragment is
just another Node
> 
> I guess I was using DocumentFragment as an easy to use NodeList, which it
is not.
> 
> Thanks for the answer anyway.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to