You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by he...@hp.com on 2000/02/29 02:02:25 UTC

elementary delete question -- DOM

If I delete a node in a DOM tree I'm assuming *all* of the children are
effectively deleted as well.  In other words, if I aim to delete an element, all
of it's associated attribute nodes and child element nodes will be "gone" too.  

Thanks,
Heather

Re: elementary delete question -- DOM

Posted by Christian Lizell <Ch...@athega.se>.
Jeff Mackay wrote:
> 
> This thread is probably off-topic for this list. I would suggest moving
> further questions to the w3-dom discussion list (see http://www.w3.org/).
> 
> > Sorry for jumping into this discussion, but when you say that the node
> > still exists after you remove it, what happens when I do the following?
> >
> >    nodeToDelete.getParentNode().deleteChildNode(nodeToDelete);
> >
> > Is it not "deleted"?
> > Can I still access nodeToDelete somehow?
> 
> The Node interface, as specified by the DOM, doesn't have a
> 'deleteChildNode' operation.  It instead has a 'removeChild' operation. The
> DOM specification intentionally left memory management details to
> implementors.
> 
> public Node removeChild(Node oldChild)
>                  throws DOMException;
> 
> The removeChild operation removes a child from a parent's child list, and
> returns it to the caller.
> With an implementation that supports garbage collection (like Java or
> JavaScript), if you don't retain a reference to the removed node, it will
> eventually be deleted. With an implementation that doesn't support garbage
> collection, it's up to the implementation to specify how the node is
> deleted.

Thank you!

This was the answer I was looking for.

/Christian

Re: elementary delete question -- DOM

Posted by Andy Heninger <he...@us.ibm.com>.
> The Node interface, as specified by the DOM, doesn't have a
> 'deleteChildNode' operation.  It instead has a 'removeChild' operation.
The
> DOM specification intentionally left memory management details to
> implementors.
>
> public Node removeChild(Node oldChild)
>                  throws DOMException;
>
> The removeChild operation removes a child from a parent's child list, and
> returns it to the caller.
> With an implementation that supports garbage collection (like Java or
> JavaScript), if you don't retain a reference to the removed node, it will
> eventually be deleted. With an implementation that doesn't support garbage
> collection, it's up to the implementation to specify how the node is
> deleted.
>

And, to answer the question specifically for the Xerces-C DOM,
it is very similar to Java.

Nodes are reference counted.  If you call DOM_Node::removeChild(),
the node removed from the document will remain available so long
as the application has a DOM_Node variable that refers to it.

When all references to the removed node(s) are dropped, the nodes themselves
will be automatically deleted by the implementation.

The same holds for the document itself; when all references to it
(in the form of DOM_Node or DOM_Document or DOM_whatever variables)
in the application code go out of scope, the document itself will
be deleted.



RE: elementary delete question -- DOM

Posted by Jeff Mackay <jm...@vtopia.com>.
This thread is probably off-topic for this list. I would suggest moving
further questions to the w3-dom discussion list (see http://www.w3.org/).


> Sorry for jumping into this discussion, but when you say that the node
> still exists after you remove it, what happens when I do the following?
>
>    nodeToDelete.getParentNode().deleteChildNode(nodeToDelete);
>
> Is it not "deleted"?
> Can I still access nodeToDelete somehow?

The Node interface, as specified by the DOM, doesn't have a
'deleteChildNode' operation.  It instead has a 'removeChild' operation. The
DOM specification intentionally left memory management details to
implementors.

public Node removeChild(Node oldChild)
                 throws DOMException;

The removeChild operation removes a child from a parent's child list, and
returns it to the caller.
With an implementation that supports garbage collection (like Java or
JavaScript), if you don't retain a reference to the removed node, it will
eventually be deleted. With an implementation that doesn't support garbage
collection, it's up to the implementation to specify how the node is
deleted.




Re: elementary delete question -- DOM

Posted by Christian Lizell <Ch...@athega.se>.
Jeff Mackay wrote:
> 
> > If I delete a node in a DOM tree I'm assuming *all* of the children are
> > effectively deleted as well.
> 
> Actually, DOM doesn't provide a way to "delete" a node. You can remove
> a node from its parent, which effectively removes the node as well as all
> of its children and attributes. But the node still exists, as do its
> children
> and attributes (perhaps to move to another portion of the document, or to
> import into another document).  I believe that any "delete" mechanism is
> implementation specific.

Sorry for jumping into this discussion, but when you say that the node
still exists after you remove it, what happens when I do the following?

    nodeToDelete.getParentNode().deleteChildNode(nodeToDelete);

Is it not "deleted"?
Can I still access nodeToDelete somehow?

/Christian

RE: elementary delete question -- DOM

Posted by Jeff Mackay <jm...@vtopia.com>.
> If I delete a node in a DOM tree I'm assuming *all* of the children are
> effectively deleted as well.

Actually, DOM doesn't provide a way to "delete" a node. You can remove
a node from its parent, which effectively removes the node as well as all
of its children and attributes. But the node still exists, as do its
children
and attributes (perhaps to move to another portion of the document, or to
import into another document).  I believe that any "delete" mechanism is
implementation specific.