PHP5 Manual Free Open Book

PHP5 Manual

PHP Manual
PrevNext

DomNode->append_child

(no version information, might be only in CVS)

DomNode->append_child --  Adds a new child at the end of the children

Description

class DOMNode {

DOMNode append_child ( DOMNode newnode )

}

This functions appends a child to an existing list of children or creates a new list of children.

Parameters

newnode

The node being appended. It can be created with e.g. DomDocument->create_element, DomDocument->create_text_node etc. or simply by using any other node.

Note: You can not append a DOMAttribute using this method. Use DomElement->set_attribute() instead.

Return Values

Returns the appended node on success or FALSE on failure.

ChangeLog

VersionDescription
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 DomNode->clone_node 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.

Examples

The following example adds a new element node to a fresh document and sets the attribute align to left.

Example 1. Adding a child

<?php
$doc
= domxml_new_doc("1.0");
$node = $doc->create_element("para");
$newnode = $doc->append_child($node);
$newnode->set_attribute("align", "left");
?>

The above example could also be written as the following:

Example 2. Adding a child

<?php
$doc
= domxml_new_doc("1.0");
$node = $doc->create_element("para");
$node->set_attribute("align", "left");
$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.

Example 3. Adding a child

<?php
include("example.inc");

if (!
$dom = domxml_open_mem($xmlstr)) {
  echo
"Error while parsing the document\n";
  exit;
}

$elements = $dom->get_elements_by_tagname("informaltable");
print_r($elements);
$element = $elements[0];

$parent = $element->parent_node();
$newnode = $parent->append_child($element);
$children = $newnode->children();
$attr = $children[1]->set_attribute("align", "left");

$xmlfile = $dom->dump_mem();
echo
htmlentities($xmlfile);
?>

The above example could also be done with DomNode->insert_before instead of DomNode->append_child.

Migrating to PHP 5

You should use DOMNode->appendChild().


     Main Menu
PHP Manual
Table of Contents
Preface
Getting Started
Language Reference
Security
Features
Function Reference
Apache-specific Functions
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Classkit Functions
Class/Object Functions
COM and .Net (Windows)
ClibPDF Functions
Crack Functions
Character Type Functions
CURL, Client URL Library Functions
Cybercash Payment Functions
Cyrus IMAP administration Functions
Date and Time Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
DB++ Functions
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
DomAttribute->name
DomAttribute->specified
DomAttribute->value
DomDocument->add_root
DomDocument->create_attribute
DomDocument->create_cdata_section
DomDocument->create_comment
DomDocument->create_element_ns
DomDocument->create_element
DomDocument->create_entity_reference
DomDocument->create_processing_instruction
DomDocument->create_text_node
DomDocument->doctype
DomDocument->document_element
DomDocument->dump_file
DomDocument->dump_mem
DomDocument->get_element_by_id
DomDocument->get_elements_by_tagname
DomDocument->html_dump_mem
DomDocument->xinclude
DomDocumentType->entities
DomDocumentType->internal_subset
DomDocumentType->name
DomDocumentType->notations
DomDocumentType->public_id
DomDocumentType->system_id
DomElement->get_attribute_node
DomElement->get_attribute
DomElement->get_elements_by_tagname
DomElement->has_attribute
DomElement->remove_attribute
DomElement->set_attribute
DomElement->tagname
DomNode->add_namespace
DomNode->append_child
DomNode->append_sibling
DomNode->attributes
DomNode->child_nodes
DomNode->clone_node
DomNode->dump_node
DomNode->first_child
DomNode->get_content
DomNode->has_attributes
DomNode->has_child_nodes
DomNode->insert_before
DomNode->is_blank_node
DomNode->last_child
DomNode->next_sibling
DomNode->node_name
DomNode->node_type
DomNode->node_value
DomNode->owner_document
DomNode->parent_node
DomNode->prefix
DomNode->previous_sibling
DomNode->remove_child
DomNode->replace_child
DomNode->replace_node
DomNode->set_content
DomNode->set_name
DomNode->set_namespace
DomNode->unlink_node
DomProcessingInstruction->data
DomProcessingInstruction->target
DomXsltStylesheet->process
DomXsltStylesheet->result_dump_file
DomXsltStylesheet->result_dump_mem
domxml_new_doc
domxml_open_file
domxml_open_mem
domxml_version
domxml_xmltree
domxml_xslt_stylesheet_doc
domxml_xslt_stylesheet_file
domxml_xslt_stylesheet
xpath_eval_expression
xpath_eval
xpath_new_context
xptr_eval
xptr_new_context
.NET Functions
Error Handling and Logging Functions
Program Execution Functions
Exif Functions
File Alteration Monitor Functions
FrontBase Functions
Forms Data Format Functions
filePro Functions
Filesystem Functions
FriBiDi Functions
FTP Functions
Function Handling Functions
Gettext
GMP Functions
HTTP Functions
Hyperwave Functions
Hyperwave API Functions
Firebird/InterBase Functions
IBM DB2, Cloudscape and Apache Derby Functions
ICAP Functions [deprecated]
iconv Functions
ID3 Functions
Informix Functions
IIS Administration Functions
Image Functions
IMAP, POP3 and NNTP Functions
PHP Options&Information
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
LDAP Functions
libxml Functions
LZF Functions
Mail Functions
mailparse Functions
Mathematical Functions
MaxDB PHP Extension
Multibyte String Functions
MCAL Functions
Mcrypt Encryption Functions
MCVE Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Mohawk Software Session Handler Functions
mSQL Functions
Microsoft SQL Server Functions
muscat Functions
MySQL Functions
Improved MySQL Extension
Ncurses Terminal Screen Control Functions
Network Functions
YP/NIS Functions
Lotus Notes Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Oracle 8 functions
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions
Output Control Functions
Object property and method call overloading
Ovrimos SQL Functions
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF functions
PDO Functions
Verisign Payflow Pro Functions
PostgreSQL Functions
POSIX Functions
Printer Functions
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
Regular Expression Functions (POSIX Extended)
Semaphore, Shared Memory and IPC Functions
SESAM Database Functions
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
Secure Shell2 Functions
Stream Functions
String Functions
Shockwave Flash Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
ODBC Functions (Unified)
URL Functions
Variable Handling Functions
vpopmail Functions
W32api Functions
WDDX Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XSL functions
XSLT Functions
YAZ Functions
Zip File Functions (Read Only Access)
Zlib Compression Functions
Zend API
PHP API: Interfaces for extension writers
FAQ: Frequently Asked Questions
Appendixes
Copyright


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele