PHP | XMLReader setParserProperty() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The XMLReader::setParserProperty() function is an inbuilt function in PHP which is used to set parser options. This function can be used to validate the document.Syntax: bool XMLReader::setParserProperty( int $property, bool $value ) Parameters: This function accepts two parameters as mentioned above and described below: $property: It specifies an integer corresponding to one of Parser Option constants as given below: XMLReader::LOADDTD (1) This will load DTD but does not validate.XMLReader::DEFAULTATTRS (2) This will load DTD and default attributes but does not validate.XMLReader::VALIDATE (3) This will load DTD and validate while parsing.XMLReader::SUBST_ENTITIES (4) This will substitute entities and expand references.$value: It specifies whether to enable or disable the property. Return Value: This function returns TRUE on success or FALSE on failure.Below examples illustrate the XMLReader::setParserProperty() function in PHP:Example 1: data.xml html <?xml version="1.0" encoding="utf-8"?> <div> <h1> Sample XML </h1> </div> index.php php <?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file with sample XML $XMLReader->open('data.xml'); // Set the Parser Property $XMLReader->setParserProperty(XMLReader::VALIDATE, true); // Check if XMLReader::VALIDATE is set or not $isProperty = $XMLReader->getParserProperty(XMLReader::VALIDATE); if ($isProperty) { echo 'Property is set.'; } ?> Output: Property is set. Program 2: data.xml html <?xml version="1.0"?> <!-- DTD rules to be followed by XML--> <!DOCTYPE html [ <!ELEMENT html (h1, p, heading, body)> <!ELEMENT h1 (#PCDATA)> <!ELEMENT p (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <!-- XML starts from here --> <html> <h1>Hi</h1> <p>World</p> <heading>GeeksforGeeks</heading> <body>Web Portal for Geeks</body> </html> index.php php <?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file $XMLReader->open('data.xml'); // Enable the Parser Property $XMLReader->setParserProperty(XMLReader::VALIDATE, true); // Iterate through the XML nodes while ($XMLReader->read()) { if ($XMLReader->nodeType == XMLREADER::ELEMENT) { // Check if XML is valid or not $isValid = $XMLReader->isValid(); if ($isValid) { echo "YES ! this node is validated<br>"; } } } ?> Output: YES ! this node is validated YES ! this node is validated YES ! this node is validated YES ! this node is validated YES ! this node is validated Reference: https://www.php.net/manual/en/xmlreader.setparserproperty.php Comment More infoAdvertise with us Next Article PHP | XMLReader setParserProperty() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-XML Similar Reads PHP | XMLReader read() Function The XMLReader::read() function is an inbuilt function in PHP which is used to move to next node in document. Thus this function is used to traverse through the XML document. Syntax: bool XMLReader::read( void ) Parameters: This function doesnât accepts any parameter. Return Value: This function retu 2 min read PHP | XMLWriter startComment() Function The XMLWriter::startComment() function is an inbuilt function in PHP which is used to start comment. This comment later needs to be closed using XMLWriter::endComment() function. Syntax: bool XMLWriter::startComment( void ) Parameters:This function doesnât accept any parameter. Return Value: This fu 2 min read PHP | XMLWriter startDocument() Function The XMLWriter::startDocument() function is an inbuilt function in PHP which is used to start the document. This document then needs to be ended with XMLWriter::endDocument function. Syntax: bool XMLWriter::startDocument( string $version, string $encoding, string $standalone ) Parameters: This functi 2 min read PHP | XMLReader next() Function The XMLReader::next() function is an inbuilt function in PHP which is used to move cursor to next node skipping all subtrees. Another usage of this function is it accepts the name of the node to directly move to the element.Syntax:Â Â bool XMLReader::next( string $localname ) Parameters: This functio 2 min read PHP | XMLWriter setIndent() Function The XMLWriter::setIndent() function is an inbuilt function in PHP which is used to toggle indentation on/off in the XML document which is off by default. Syntax: bool XMLWriter::setIndent( bool $indent ) Parameters: This function accepts a single parameter $indent which holds a boolean stating TRUE 2 min read PHP | xml_parser_set_option() Function Pre-requisite: XML Basics The xml_parser_set_option() function is an inbuilt function in PHP which is used to set the options in an XML parser. Syntax: bool xml_parser_set_option( resource $parser, int $specified_option, mixed $option_value) Parameters: This function accepts three parameters as ment 2 min read PHP | XMLWriter startCdata() Function The XMLWriter::startCdata() function is an inbuilt function in PHP which is used to start the CDATA. This element then needs to be closed with XMLWriter::endCdata() function. CDATA is a block of text which is not parsed by the parser but are recognized as markup. Syntax: bool XMLWriter::startCdata( 2 min read PHP | XMLWriter startAttribute() Function The XMLWriter::startAttribute() function is an inbuilt function in PHP which is used to start attribute. This attribute can be later closed with XMLWriter::endAttribute() function. Syntax: bool XMLWriter::startAttribute( string $name ) Parameters: This function accepts a single parameter $name which 2 min read PHP | XMLReader moveToAttribute() Function The XMLReader::moveToAttribute() function is an inbuilt function in PHP which is used to move cursor to a named attribute. Syntax: bool XMLReader::moveToAttribute( string $name ) Parameters: This function accepts a single parameter $name which holds the name of the attribute. Return Value: This func 2 min read PHP | XMLReader lookupNamespace() Function The XMLReader::lookupNamespace() function is an inbuilt function in PHP which is used to lookup in scope namespace for a given prefix. Syntax: string XMLReader::lookupNamespace( string $prefix ) Parameters: This function accepts a single parameter $prefix which holds the string containing the prefix 1 min read Like