W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2011

[DOMCore] takeChildNodes() method

From: Ralph Ritoch <rritoch@gmail.com>
Date: Sat, 22 Jan 2011 20:51:29 -0700
Message-ID: <AANLkTin4bwLSM1Mt3+ddANYhKhbzAghS4UfaPaMFKFug@mail.gmail.com>
To: public-webapps@w3.org
I would like to submit to you a possible addition to the DOM specification
based on discoveries I made while developing a new protocol named XRDOM.

Revision: Added that all Attr nodes of decedent nodes are carried to their
new location.

The addition is a method named takeChildNodes which should be added to the
Node interface. This method makes it more possible to easily move data
around the document with linear code that does not require any flow control
statements (loops). One example would be to move a nodes children to its
parent node and then remove the node itself. I have been using this method
to replace an element with another element, including the attributes while
not affecting the position of the hostNodes child nodes in the document.
The takeChildNodes method can also be used in conjunction with the cloneNode
function to copy attribute values or to provide more easily cut,copy, and
paste functionality.  The takeChildNodes method returns the node itself for
convenience and must remove the nodes from the hostNode, as cloneNode can be
used in conjunction for the purpose of copying only the child nodes.

See related XRDOM Notes:
http://wiki.vnetpublishing.com/XRDOM_(XML_Rest_Dom_API)#Notes

<http://wiki.vnetpublishing.com/XRDOM_%28XML_Rest_Dom_API%29#Notes>

Recommendation:

  interface Node
<http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html#interface-node>
{

    ...

    Node <http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html#interface-node>
                           takeChildNodes(Node
<http://dev.w3.org/2006/webapi/DOM4Core/DOM4Core.html#interface-node>
hostNode);

    ...
  };


takeChildNodes
This method removes all child nodes from the provided hostNode and appends
them to the end of the list of children of this node in the same order they
were in the original hostNode. This method does not remove Attr nodes from
the hostNode and Attr nodes are not added to the current node. The child
nodes being moved carry with them all of their decedents including
attributes and Attr nodes.

*Parameters*
hostNode of type NodeThe Node to remove children from.
*Return Value*

Node

The current Node which now has the child nodes from the hostNode.
*Exceptions*
*

DOMException <http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-17189187>

HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow
children of the type of the node(s) received from the hostNode, or if the
node to append is one of this node's
ancestors<http://www.w3.org/TR/DOM-Level-3-Core/glossary.html#dt-ancestor>
or
this node itself, or if this node is of type
Document<http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document>
and
the DOM application attempts to append a second
DocumentType<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-412266927>
 or Element <http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-745549614>
 node.

WRONG_DOCUMENT_ERR: Raised if a hostNode was created from a different
document than the one that created this node.

NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or if the
previous parent of the node being inserted is readonly.

NOT_SUPPORTED_ERR: this exception might be raised if the DOM implementation
doesn't support the moving of the
DocumentType<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-412266927>
child
or Element <http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-745549614>
 child.
*

---

Please send any issues related to this suggestion to rritoch@gmail.com .

Best Regards,
 Ralph Ritoch
 http://www.vnetpublishing.com
Received on Sunday, 23 January 2011 13:39:37 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:43 GMT