Web студия "GrandView"
  Главная   Написать Контакты
   
   
О проекте
Руководство php
 

DOMNode->cloneNode()

(no version information, might be only in CVS)

DOMNode->cloneNode() --  Clones a node

Описание

class DOMNode {

DOMNode cloneNode ( [bool deep] )

}

Creates a copy of the node.

Список параметров

deep

Indicates whether to copy all descendant nodes. This parameter is defaulted to FALSE.

Возвращаемые значения

The cloned node.



add a note add a note User Contributed Notes
DOMNode->cloneNode()
oliver dot christen at camptocamp dot com
19-Nov-2004 08:48
simple exemple of node cloning

<?xml version="1.0"?>

<book type="paperback">
    <title name='MAP'>Red Nails</title>
    <price>$12.99</price>
    <author>
        <name first="Robert" middle="E" last="Howard"/>
        <birthdate>9/21/1977</birthdate>
    </author>
    <author>
        <name first="Arthur" middle="Mc" last="Kayn"/>
    </author>
</book>

<?php

//filename xml file to use
$file = 'book.xml';

$doc = new domDocument;

if (
file_exists($file)) {
   
$doc->load($file);
} else {
    exit(
'Erreur !.');
}

$xpath = new domXPath($doc);

$query = "//author/*";
$xpathQuery = $xpath->query($query);

$size = $xpathQuery->length;
for (
$i=0; $i<$size; $i++){
   
$node = $xpathQuery->item($i);
    if (
$node->nodeName == 'birthdate' && $node->hasChildNodes() && $node->firstChild->textContent != ''){
       
$clonenode = $node->cloneNode(true);
       
$refnode = $node;
    }
}
for (
$i=0; $i<$size; $i++){
   
$node = $xpathQuery->item($i);
    if (!
$node->isSameNode($refnode)){
       
$newnode = $node->appendChild($clonenode);
    }
}

print
$doc->saveXML();

?>
dtorop932 at hotmail dot com
18-Oct-2004 10:44
For those converting from PHP 4 DOM XML to PHP 5 DOM extension:

In the old days, DOM XML's clone_node() was the way to copy nodes from one DOM to another, as well as to perform intra-DOM copies.  Nowadays, DOM's cloneNode() is the intra-DOM solution, but see importNode() (http://php.net/dom-domdocument-importnode) to copy nodes from one DOM to another.

So to append root node of $dom2 and all its children into root node of $dom1:

PHP 4 (DOM XML):

<?
$root1 = $dom1->document_element();
$other_node = $dom2->document_element();
$root1->append_child($other_node->clone_node(true));
?>

PHP 5 (DOM):

<?
$dom1->documentElement->appendChild(
  $dom1->importNode($dom2->documentElement, true));
?>

DOMNode->hasAttributes()> <DOMNode->appendChild()
Last updated: Fri, 26 Jan 2007
 
 
Новости
11 июля 2007
Сайт запущен
© 2007 info@grandviewstudio.com

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 324

Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/sites/grandviewstudiocom/www/65f67d67a94ad980786580ae69e11c07/sape.php on line 330
Z058440144362 Z348613067571