[Zope-dev] XML Document appendChild questions

Martijn Faassen M.Faassen@vet.uu.nl
Tue, 27 Jul 1999 18:01:54 +0200


Hi there,

I've been experimenting with manipulating XML documents in Zope. At
first, it seemed to work:

I made an XML document called 'testdoc' with the following content:

<?xml version="1.0"?>
<list>
<li>Zero</li>
<li>One</li>
<li>Two</li>
<li>Three</li>
</list>

And I made another one called 'someElement' with the following content:
<?xml version="1.0"?>
<li>Another list item</li>

Then I made a DTML method called 'testInsert' (actually I'm appending),
doing
the following:

<!--#var standard_html_header-->
<!--#call "testdoc[0].appendChild(someElement[0])"-->
<p>Done insertion</p>
<!--#var standard_html_footer-->

This indeed adds the new element to the <list> in the testdoc.

However, the <li>Another list item</li> disappears from someElement! Is
this what should happen? A clue can be found in the XML Document source
(Node.py):

def appendChild(self, newChild):
        """
        Adds the node newChild to the end of the list of children of
this node.
        If the newChild is already in the tree, it is first removed. 
        """

But in this case 'newChild' is in *another* tree and it is removed as
well. Is this intentionally? It seems as if it would be difficult to
build trees now, or am I doing something wrong and shouldn't I use XML
Documents for XML fragments that I want to insert? I think it may in
fact be hard to determine if a cross-tree append is taking place,
efficiently at least; right now it is only checked if the newChild to be
inserted has a parentNode at all (and removes it from that parent node
if so).

Regards,

Martijn