PHP | DOMDocumentFragment appendXML() Function Last Updated : 20 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 function returns TRUE on success or FALSE on failure. Below given programs illustrate the DOMDocument::appendXML() function in PHP: Program 1: php <?php // Create a new DOMDocument $doc = new DOMDocument; // Load the XML $doc->loadXML("<root/>"); // Create a Document Fragment $f = $doc->createDocumentFragment(); // Append the XML to fragment $f->appendXML( "<h1>Heading 1</h1><strong>Strong text</strong>"); // Append the fragment to document $doc->documentElement->appendChild($f); // Save the XML echo $doc->saveXML(); ?> Output: <?xml version="1.0"?> <root><h1>Heading 1</h1><strong>Strong text</strong></root> Program 2: php <?php // Create a new DOMDocument $doc = new DOMDocument; // Load the XML $doc->loadXML("<root/>"); // Create a Document Fragment $f = $doc->createDocumentFragment(); // Append the XML to fragment $f->appendXML("<h1 style=\"color: red\"> Red </h1>"); $f->appendXML("<h1 style=\"color: green\"> Green </h1>"); $f->appendXML("<h1 style=\"color: blue\"> Blue </h1>"); // Append the fragment to document $doc->documentElement->appendChild($f); // Save the XML echo $doc->saveXML(); ?> Output: <?xml version="1.0"?> <root> <h1 style="color: red"> Red </h1> <h1 style="color: green"> Green </h1> <h1 style="color: blue"> Blue </h1> </root> Reference: https://www.php.net/manual/en/domdocumentfragment.appendxml.php Comment More infoAdvertise with us Next Article PHP | DOMDocumentFragment appendXML() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads 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 | DOMDocument createDocumentFragment() Function The DOMDocument::createDocumentFragment() function is an inbuilt function in PHP which is used to create a new document fragment. Syntax: DOMDocumentFragment DOMDocument::createDocumentFragment( void ) Parameters: This function doesnât accepts any parameters. Return Value: This function returns a ne 2 min read PHP | DOMNode appendChild() function 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 2 min read PHP | DOMDocument createComment() Function The DOMDocument::createComment() function is an inbuilt function in PHP which is used to create a new instance of class createComment. Syntax: DOMComment DOMDocument::createComment( string $data ) Parameters: This function accepts single parameter $data which holds the content of the comment node. R 2 min read PHP | DOMDocument createElement() Function The DOMDocument::createElement() function is an inbuilt function in PHP which is used to create a new instance of class DOMElement. Syntax: DOMElement DOMDocument::createElement( string $name, string $value ) Parameters: This function accepts two parameters as mentioned above and described below: $n 2 min read Like