PHP | DOMNode appendChild() function Last Updated : 19 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The DOMNode::appendChild() function is an inbuilt function in PHP which is used to appends a child to an existing list of children or creates a new list of children. The child can be created with DOMDocument::createElement(), DOMDocument::createTextNode() or by using any other node. Syntax: DOMNode DOMNode::appendChild( DOMNode $newnode ) Parameters:This function accepts a single parameter $newnode which holds the node to append. Return Value: This function returns the node which is added. Exceptions: This function throws DOM_NO_MODIFICATION_ALLOWED_ERR, if the node is readonly or if the previous parent of the node being inserted is readonly or DOM_HIERARCHY_REQUEST_ERR, if the node is of a type that does not allow children of the type of the $newnode node, or if the node to append is one of this node's ancestors or this node itself or DOM_WRONG_DOCUMENT_ERR, if $newnode was created from a different document than the one that created this node. Below given programs illustrate the DOMNode::appendChild() function in PHP: Program 1: php <?php // Create a new DOMDocument $doc = new DOMDocument(); // Create an Element $node = $doc->createElement("em", "GeeksforGeeks"); // Append the child $newnode = $doc->appendChild($node); // Render the XML echo $doc->saveXML(); ?> Output: GeeksforGeeks Program 2: php <?php // Create a new DOMDocument $doc = new DOMDocument(); // Create an Table element $table = $doc->createElement("table"); // Append the child $tablenode = $doc->appendChild($table); // Create a tr element $tr = $doc->createElement("tr"); // Append the child $tablenode->appendChild($tr); // Create a th element $th = $doc->createElement("th", "Name"); // Set the attribute $th->setAttribute("style", "border: 1px solid #dddddd;"); // Append the child $tr->appendChild($th); // Create a tr element $tr = $doc->createElement("tr"); // Append the child $tablenode->appendChild($tr); // Create a th element $th = $doc->createElement("td", "GeeksforGeeks"); // Set the attribute $th->setAttribute("style", "background-color: #dddddd;border: 1px solid #dddddd;"); // Append the child $tr->appendChild($th); // Render the XML echo $doc->saveXML(); ?> Output: Reference: https://www.php.net/manual/en/domnode.appendchild.php Comment More infoAdvertise with us Next Article PHP | DOMNode appendChild() function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMNode C14NFile() Function The DOMNode::C14NFile() function is an inbuilt function in PHP which is used to canonicalize nodes to a file. Syntax: int DOMNode::C14NFile( string $uri, bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts five parameters as mentioned above and 2 min read PHP | DOMNode cloneNode() function The DOMNode::cloneNode() function is an inbuilt function in PHP which is used to create a copy of the node. Syntax: DOMNode DOMNode::cloneNode( bool $deep ) Parameters:This function accepts a single parameter $deep which indicates whether to copy all descendant nodes. This parameter is set to FALSE 1 min read PHP | DOMNode C14N() Function The DOMNode::C14N() function is an inbuilt function in PHP which is used to convert a node into string. Syntax: string DOMNode::C14N( bool $exclusive, bool $with_comments, array $xpath, array $ns_prefixes ) Parameters: This function accepts four parameters as mentioned above and described below: $ex 2 min read PHP | DOMDocumentFragment appendXML() Function The DOMDocument::appendXML() function is an inbuilt function in PHP which is used to append raw XML data to a DOMDocumentFragment. Syntax: bool DOMDocumentFragment::appendXML( string $data ) Parameters: This function accepts a single parameter $data which holds the XML to append. Return Value: This 1 min read PHP | DOMCharacterData appendData() Function The DOMCharacterData::appendData() function is an inbuilt function in PHP which is used to append the string to the end of the character data of the node. Syntax: public DOMCharacterData::appendData( string $data ) Parameters: This function accepts a single parameter $data which holds the string tha 2 min read PHP | DOMNamedNodeMap count() Function The DOMNamedNodeMap::count() function is an inbuilt function in PHP which is used to get the number of nodes in the map. It can be used to count attributes of a element. Syntax: int DOMNamedNodeMap::count( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function re 2 min read PHP | DOMDocument createTextNode() Function The DOMDocument::createTextNode() function is an inbuilt function in PHP which is used to create a new instance of class DOMText. Syntax: DOMText DOMDocument::createTextNode( string $content ) Parameters: This function accepts single parameter $content which holds the content of the text. Return Val 1 min read PHP | DOMComment __construct() Function The DOMComment::__construct() function is an inbuilt function in PHP which creates a new DOMComment object. This object is read only and can be appended to a document Syntax: public DOMComment::__construct( string $value) Parameters: This function accepts a single parameter $value which holds the co 1 min read PHP | DOMNode normalize() Function The DOMNode::normalize() function is an inbuilt function in PHP which is used to remove empty text nodes and merge adjacent text nodes in this node and all its children. Syntax: void DOMNode::normalize( void ) Parameters: This function doesnât accept any parameters. Return Value: This function does 2 min read PHP | DOMNode getLineNo() function The DOMNode::getLineNo() function is an inbuilt function in PHP which is used to get the line number for where the node is defined. Syntax: DOMNode DOMNode::getLineNo( void ) Parameters:This function doesnât accept any parameter. Return Value: This function returns the line number where the node was 2 min read Like