PHP | DOMDocument relaxNGValidate() Function Last Updated : 20 Feb, 2020 Comments Improve Suggest changes Like Article Like Report 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 $filename ) Parameters: This function accepts a single parameter $filename which holds the RNG file. Return Value: This function returns TRUE on success or FALSE on failure. Below given programs illustrate the DOMDocument::relaxNGValidate() function in PHP: Program 1: File name: rule.rng php <element name="college" xmlns="http://relaxng.org/ns/structure/1.0"> <zeroOrMore> <element name="rollno"> <element name="name"> <text/> </element> <element name="subject"> <text/> </element> </element> </zeroOrMore> </element> File name: index.php php <?php // Create a new DOMDocument $doc = new DOMDocument; // Load the XML $doc->loadXML("<?xml version=\"1.0\"?> <college> <rollno> <name>John Smith</name> <subject>Web</subject> </rollno> <rollno> <name>John Doe</name> <subject>CSE</subject> </rollno> </college>"); // Check if XML follows the relaxNG rule if ($doc->relaxNGValidate('rule.rng')) { echo "This document is valid!\n"; } ?> Output: This document is valid! Program 2: File name: rule.rng php <element name="company" xmlns="http://relaxng.org/ns/structure/1.0"> <zeroOrMore> <element name="employee"> <element name="name"> <text/> </element> <element name="salary"> <text/> </element> </element> </zeroOrMore> </element> File name: index.php php <?php // Create a new DOMDocument $doc = new DOMDocument; // Load the XML $doc->loadXML("<?xml version=\"1.0\"?> <company> <employee> <name>John Smith</name> <salary>Web</salary> </employee> <employee> <!-- Do not add salary to voilate rule --> <name>John Doe</name> </employee> </company>"); // Check if XML doesn't follows the relaxNG rule if (!$doc->relaxNGValidate('rule.rng')) { echo "This document is not valid!\n"; } ?> Output: This document is not valid! Reference: https://www.php.net/manual/en/domdocument.relaxngvalidate.php Comment More infoAdvertise with us Next Article PHP | DOMDocument relaxNGValidate() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DOM Similar Reads PHP | DOMDocument relaxNGValidateSource() Function The DOMDocument::relaxNGValidateSource() function is an inbuilt function in PHP which is used to perform relaxNG validation on the document using a string as RNG schema. The difference between relaxNGValidate() and relaxNGValidateSource() is that the former accepts a rng schema filename whereas latt 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 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 schemaValidateSource() Function The DOMDocument::schemaValidateSource() function is an inbuilt function in PHP which is used to validate a document based on a schema defined in the given string. The difference between schemaValidate() and schemaValidateSource() is that the former accepts a schema filename whereas latter can accept 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 Like