From 13156130e1f68452f1ce4507b48df925250064f0 Mon Sep 17 00:00:00 2001 From: Mehdi Achour Date: Sun, 12 Jun 2005 19:07:02 +0000 Subject: [PATCH] Switched DOMNode->append_child() and DOMNode->add_namespace() to the new structure Added another changelog for append_child Added a refsect1 named migration describing how to jump from domxml to dom Added user comments git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@188227 c90b9560-bf6c-de11-be94-00142212c4b1 --- .../functions/DomNode-add-namespace.xml | 77 +++++++- .../domxml/functions/DomNode-append-child.xml | 175 +++++++++++++----- 2 files changed, 200 insertions(+), 52 deletions(-) diff --git a/reference/domxml/functions/DomNode-add-namespace.xml b/reference/domxml/functions/DomNode-add-namespace.xml index c4280beab9..a3d148e8a8 100644 --- a/reference/domxml/functions/DomNode-add-namespace.xml +++ b/reference/domxml/functions/DomNode-add-namespace.xml @@ -1,5 +1,5 @@ - + DomNode->add_namespace @@ -7,18 +7,77 @@ Adds a namespace declaration to a node - + &reftitle.description; - - boolDomNode->add_namespace - stringuri - stringprefix - + + DOMNode + + booladd_namespace + stringuri + stringprefix + + + This method adds a namespace declaration to a node. + + + This method is not part of the DOM specification. + + + + + &reftitle.parameters; - See also domdocument_create_element_ns, and - domnode_set_namespace + + + uri + + + The namespace URI of the node. + + + + + prefix + + + The namespace prefix of the node. If not set, a random prefix will be + generated. + + + + + + + + &reftitle.returnvalues; + + &return.success; + + + + Migrating to PHP 5 + + You can set the namespace URI and prefix of a DOMElement + or a DOMAttr at creation time by using + or + . + + + + Remember the an attribute does not inherit its namespace from the element + it is attached to. + + + + + &reftitle.seealso; + + + + + diff --git a/reference/domxml/functions/DomNode-append-child.xml b/reference/domxml/functions/DomNode-append-child.xml index c5b2973173..4dde444357 100644 --- a/reference/domxml/functions/DomNode-append-child.xml +++ b/reference/domxml/functions/DomNode-append-child.xml @@ -1,49 +1,119 @@ - + DomNode->append_child - Adds new child at the end of the children + Adds a new child at the end of the children - + &reftitle.description; - - domelementDomNode->append_child - domelementnewnode - + + DOMNode + + DOMNodeappend_child + DOMNodenewnode + + This functions appends a child to an existing list of children or creates - a new list of children. The child can be created with e.g. - domdocument_create_element, - domdocument_create_text etc. or simply by using any - other node. + a new list of children. + + + + &reftitle.parameters; + + + + newnode + + + The node being appended. It can be created with e.g. + , + etc. or + simply by using any other node. + + + + You can not append a DOMAttribute using this + method. Use + instead. + + + + + + + + + &reftitle.returnvalues; + + Returns the appended node on success or &false; on failure. + + + + &reftitle.changelog; + + + + + + &Version; + &Description; + + + + + 4.3.0 + + You are not allowed anymore to insert a node from another document. + + + + 4.3.0 + + Prior to PHP 4.3.0, the new child is duplicated before being + appended. + Therefore the new child is a completely new copy which can be + modified without changing the node which was passed to this function. + If the node passed has children itself, they will be duplicated as + well, which makes it quite easy to duplicate large parts of an XML + document. The return value is the appended child. If you plan to do + further modifications on the appended child you must use the returned + node. + + + + 4.3.0 and 4.3.1 + + The new child newnode is first unlinked from + its existing context, if it's already a child of DomNode. Therefore + the newnode is moved and not copies anymore. + This is the behaviour according to the W3C specifications. If you + need the old behaviour, use before appending. + + + + 4.3.2 + + The new child newnode is first unlinked from + its existing context, if it's already in the tree. Same rules apply. + + + + + + + + + &reftitle.examples; + + The following example adds a new element node to a fresh document and sets + the attribute align to left. - (PHP < 4.3) Before a new child is appended it is first duplicated. Therefore the new - child is a completely new copy which can be modified without changing the - node which was passed to this function. If the node passed has children - itself, they will be duplicated as well, which makes it quite easy to - duplicate large parts of an XML document. The return value is the - appended child. If you plan to do further modifications on the appended - child you must use the returned node. - - - (PHP 4.3.0/4.3.1) The new child newnode is first - unlinked from its existing context, if it's already a child of DomNode. - Therefore the node is moved and not copies anymore. - - - (PHP >= 4.3.2) The new child newnode is first - unlinked from its existing context, if it's already in the tree. Therefore - the node is moved and not copied. This is the behaviour according to the - W3C specifications. If you want to duplicate large parts of an XML document, - use DomNode->clone_node() before appending. - - - The following example will add a new element node to a fresh document - and sets the attribute "align" to "left". Adding a child @@ -57,7 +127,11 @@ $newnode->set_attribute("align", "left"); ]]> + + The above example could also be written as the following: + + Adding a child @@ -71,10 +145,14 @@ $newnode = $doc->append_child($node); ]]> + + A more complex example is the one below. It first searches for a certain element, duplicates it including its children and adds it as a sibling. - Finally a new attribute is added to one of the children of the new - sibling and the whole document is dumped. + Finally a new attribute is added to one of the children of the new sibling + and the whole document is dumped. + + Adding a child @@ -96,21 +174,32 @@ $newnode = $parent->append_child($element); $children = $newnode->children(); $attr = $children[1]->set_attribute("align", "left"); -echo "
";
 $xmlfile = $dom->dump_mem();
 echo htmlentities($xmlfile);
-echo "
"; ?> ]]>
- The above example could also be done with - domnode_insert_before instead of - domnode_append_child.
- See also domnode_insert_before, and - domnode_clone_node. + The above example could also be done with + instead of + . + +
+ + Migrating to PHP 5 + + You should use . + + + + &reftitle.seealso; + + + + +