PHP | XMLReader read() Function Last Updated : 27 Mar, 2020 Comments Improve Suggest changes Like Article Like Report 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 returns TRUE on success or FALSE on failure. Below given programs illustrate the XMLReader::read() function in PHP: Program 1: In this program, we will get the value of a element after traversing the file data.xml Filename: data.xml html <?xml version="1.0" encoding="utf-8"?> <div1> <h1> GeeksforGeeks </h1> </div1> Filename: index.php php <?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file $XMLReader->open('data.xml'); // Iterate through the XML nodes to // reach the h1 element's text // (Only four times) $XMLReader->read(); $XMLReader->read(); $XMLReader->read(); $XMLReader->read(); // Print the value of element echo "The text inside is: " . "$XMLReader->value<br>"; ?> Output: GeeksforGeeks Program 2: In this program, we will get the name of an element after traversing to it. Filename: data.xml html <?xml version="1.0" encoding="utf-8"?> <div1> <h1> GeeksforGeeks </h1> </div1> Filename: index.php php <?php // Create a new XMLReader instance $XMLReader = new XMLReader(); // Open the XML file $XMLReader->open('data.xml'); // Iterate through the XML nodes // to reach the h1 element // (only three times) $XMLReader->read(); $XMLReader->read(); $XMLReader->read(); // Print name of element echo "The name of element is: " . "$XMLReader->name<br>"; ?> Output: The name of element is: h1 Reference: https://www.php.net/manual/en/xmlreader.read.php Comment More infoAdvertise with us Next Article PHP | XMLReader read() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads 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 | readfile( ) Function The readfile() function in PHP reads a file and writes its contents directly to the output buffer (usually the browser). Itâs an easy way to show a file without reading it line by line yourself.If thereâs a problem reading the file, like if it doesnât exist, PHP will usually show an error message. T 3 min read PHP | XMLReader isValid() Function The XMLReader::isValid() function is an inbuilt function in PHP which is used to check if the document being parsed is valid or not. An XML is valid if it is written by following a DTD (Document Type Definition) which defines all the allowed elements and the structure of elements. Syntax: bool XMLRe 2 min read PHP | XMLReader setParserProperty() Function 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 ab 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 Like