Re: [xml] redicting parts of trees



Martijn Faassen wrote:
Daniel Veillard wrote:
[snip]
I think that if we add this then we should try to match the existing
semantic of those operation in PHP for example.

Does PHP implement this operation on top of libxml2? We might also want
to consider the W3C importNode semantic, though I doubt it actually says
much of use for us here...

Coming back to this myself:

I just checked the dom module of PHP5, and found the implementation of what looks to be importNode. Unfortunately it doesn't do what I want, as it merely seems to use xmlDocCopyNode, creating a new copy of the node, instead of actually moving the existing node. PHP 5's semantic in this is compatible with the behavior of importNode as in the W3C DOM, which defines importNode like this:

  Imports a node from another document to this document, without
altering or removing the source node from the original document; this
method creates a new copy of the source node.

the semantic that we're talking about here is to adopt a node from another document. The W3C DOM level 3 does provide an operation for this, on the Document interface:

adoptNode introduced in DOM Level 3

Attempts to adopt a node from another document to this document. If supported, it changes the ownerDocument of the source node, its children, as well as the attached attribute nodes if there are any. If the source node has a parent it is first removed from the child list of its parent. This effectively allows moving a subtree from one document to another (unlike importNode() which create a copy of the source node instead of moving it).

More info:

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-adoptNode

My hopes went up for a minute when I grepped PHP's implementation of the DOm and found it did have a reference to adoptNode, but I found this:

/* {{{ proto DOMNode dom_document_adopt_node(DOMNode source);
URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-Document3-adoptNode
Since: DOM Level 3
*/
PHP_FUNCTION(dom_document_adopt_node)
{
 DOM_NOT_IMPLEMENTED();
}
/* }}} end dom_document_adopt_node */

So that doesn't help us very much here. :)

Regards,

Martijn



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]