PHP | DOMDocument xinclude() Function Last Updated : 26 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 Value: This function returns the number of XIncludes in the document, -1 if some processing failed, or FALSE if there were no substitutions. Below examples illustrate the DOMDocument::xinclude() function in PHP: Example 1: In this program, we will include from XML from new.xml to index.php. new.xml php <?xml version='1.0'?> <disclaimer> <p> This is the content from new.xml included using xinclude. </p> </disclaimer> index.php php <?php $xml = <<<EOD <?xml version="1.0" ?> <root xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="new.xml"> </xi:include> </root> EOD; // Create a new DOMDocument $dom = new DOMDocument(); // let's have a nice output $dom->preserveWhiteSpace = false; $dom->formatOutput = true; // load the XML string defined above $dom->loadXML($xml); // substitute xincludes $dom->xinclude(); echo $dom->saveXML(); ?> Output: This is the content from new.xml included using xinclude. Example 2: In this program, we will add a fallback if xinclude fails. index.php php <?php $xml = <<<EOD <?xml version="1.0" ?> <root xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="wrong_name.xml"> <xi:fallback> <error>xml not found</error> </xi:fallback> </xi:include> </root> EOD; // Create a new DOMDocument $dom = new DOMDocument(); // let's have a nice output $dom->preserveWhiteSpace = false; $dom->formatOutput = true; // load the XML string defined above $dom->loadXML($xml); // substitute xincludes $dom->xinclude(); echo $dom->saveXML(); ?> Output: xml not found Reference: https://www.php.net/manual/en/domdocument.xinclude.php Comment More infoAdvertise with us Next Article PHP | DOMDocument xinclude() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads 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 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 saveXML() Function 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 functio 2 min read PHP | DOMDocument relaxNGValidate() Function The DOMDocument::relaxNGValidate() function is an inbuilt function in PHP which is used to performs relaxNG validation on the document. The relaxNG is an alternative to DDT and defines a structure which needs to be followed by the XML document. Syntax: bool DOMDocument::relaxNGValidate( string $file 2 min read PHP | DOMDocument schemaValidate() Function The DOMDocument::schemaValidate() function is an inbuilt function in PHP which is used to validate a document based on the given schema file. The schema file can be in an XSD format which is the recommendation from W3C (World Wide Web Consortium). Syntax: bool DOMDocument::schemaValidate( string $fi 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 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 | XMLWriter endDocument() Function The XMLWriter::endDocument() function is an inbuilt function in PHP which is used to end current document. Syntax: bool XMLWriter::endDocument( void ) Parameters: This function doesnât accept any parameter. Return Value: This function returns TRUE on success or FALSE on failure. Below examples illus 1 min read PHP | DOMDocument load() Function The DOMDocument::load() function is an inbuilt function in PHP which is used to load an XML document from a file. Syntax: mixed DOMDocument::load( string $filename, int $options = 0 ) Parameters: This function accepts two parameters as mentioned above and described below: $filename: This parameter h 1 min read PHP | DOMDocument registerNodeClass() Function The DOMDocument::registerNodeClass() function is an inbuilt function in PHP which is used to register extended class used to create base node type. Syntax: bool DOMDocument::registerNodeClass( string $baseclass, string $extendedclass ) Parameters: This function accept two parameters as mentioned abo 2 min read Like