- From: Olli Pettay <Olli.Pettay@helsinki.fi>
- Date: Sun, 23 Jan 2011 19:37:45 +0200
- To: Ralph Ritoch <rritoch@gmail.com>
- CC: public-webapps@w3.org
Hi, takeChildNodes() could be useful in some cases, but it is already easy to achieve the same without any loops. Something like: var r = document.createRange(); r.selectNodeContents(originalParent); destinationParent.appendChild(r.extractContents()); So since it is already easy to move a group of nodes, and with range object it is possible to define the group to contain also something else than just child nodes, the use cases for takeChildNodes() should be good, IMO. -Olli On 01/23/2011 05:51 AM, Ralph Ritoch wrote: > 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: > > interfaceNode <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 |Node| > The 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 > <mailto:rritoch@gmail.com> . > > Best Regards, > Ralph Ritoch > http://www.vnetpublishing.com <http://www.vnetpublishing.com/>
Received on Sunday, 23 January 2011 17:38:17 UTC