PHP | DOMDocument saveXML() Function Last Updated : 29 Mar, 2023 Comments Improve Suggest changes Like Article Like Report The DOMDocument::saveXML() function is an inbuilt function in PHP which is used to create an XML document from the DOM representation. This function is used after building a new dom document from scratch. Syntax: string DOMDocument::saveXML( DOMNode $node, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $node: This parameter is used for output only for specific node without XML declaration rather than the entire document.$options: This parameter adds the additional options. Currently this parameter supports only LIBXML_NOEMPTYTAG. Return Value: This function returns the XML document on success or FALSE on failure. Below programs illustrate the DOMDocument::saveXML() function in PHP: Program 1: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Use createTextNode() function to create a text node $domTN = $domDocument->createTextNode('GeeksforGeeks'); // Append element to the document $domDocument->appendChild($domTN); // Use saveXML() function to save the XML document echo $domDocument->saveXML(); ?> Output:<?xml version="1.0" encoding="iso-8859-1"?> GeeksforGeeks Program 2: php <?php // Create a new DOMDocument $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Use createElement() function to create an element node $domElement = $domDocument->createElement('organization', 'GeeksforGeeks'); // Append element to the document $domDocument->appendChild($domElement); // Use saveXML() function to save a XML document echo $domDocument->saveXML(); ?> Output:<?xml version="1.0" encoding="iso-8859-1"?> <organization>GeeksforGeeks</organization> Reference: https://www.php.net/manual/en/domdocument.savexml.php Comment More infoAdvertise with us Next Article PHP | DOMDocument saveXML() Function jit_t Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | DOMDocument save() Function The DOMDocument::save() function is an inbuilt function in PHP which is used to create an XML document from the DOM representation. This function is used after creating the new dom document from scratch. Syntax: int DOMDocument::save( string $filename, int $options = 0 ) Parameters: This function ac 2 min read PHP DOMDocument saveHTML() Function The DOMDocument::saveHTML() function is an inbuilt function in PHP that is used to create an HTML document from the DOM representation. This function is used after building the dom document from scratch. Syntax: string DOMDocument::saveHTML( DOMNode $node = NULL ) Parameters: This function accepts s 2 min read PHP DOMDocument saveHTMLFile() Function The DOMDocument::saveHTMLFile() function is an inbuilt function in PHP that is used to create an HTML document from the DOM representation. This function is used after creating the dom document. Syntax: int DOMDocument::saveHTMLFile( string $filename ) Parameters: This function accepts a single para 2 min read PHP | DOMDocument xinclude() Function The DOMDocument::xinclude() function is an inbuilt function in PHP which is used to substitute the XIncludes in a DOMDocument Object. Syntax: int DOMDocument::xinclude( int $options = 0 ) Parameters: This function accepts an optional single parameter $options which holds the libxml parameter. Return 2 min read PHP | DOMDocument validate() Function The DOMDocument::validate() function is an inbuilt function in PHP which is used to validate the document based on its DTD (Document Type Definition). DTD defines the rules or structure to be followed by the XML file and if a XML document doesn't follows this format then this function will return fa 2 min read Like