• PHP Video Tutorials

PHP - XMLReader::isValid() Function



Definition and Usage

XML is a mark-up language to share the data across the web, XML is for both human read-able and machine read-able. XMLReader extension is used to read/retrieve the contents of an XML document i.e. using the methods of the XMLReader class you can read each node of an XML document.

The XMLReader:: isValid() function of the XMLReader class is used to verify whether current node of the read/parsed document is valid.

Syntax

XMLReader::isValid();

Parameters

This function does not accept any parameters.

Return Values

This function returns a boolean value which is TRUE if the parsed document is valid and FALSE in case it is invalid.

PHP Version

This function was first introduced in PHP Version 5 and works in all the later versions.

Example

Following example demonstrates the usage of the XMLReader::isValid() function −data.xml

<dataaa> 
   <name>Raju</name> 
   <age>32</age> 
   <phone>9848022338</phone> 
	<city>Hyderabad</city>
</data> 

sample.php

<?php
   //Creating an XMLReader
   $reader = new XMLReader();

   //Opening a reader
   $reader->open("test.xml");

   //Setting the parser property
   //$xml->setParserProperty($reader->VALIDATE, true);
   $bool = $reader->isValid();
   
   if($bool){
      print("Current node is valid");
   } else {
      print("Current node is invalid");
   }

   //Closing the reader
   $reader->close();
?> 

This will produce following result −

Current node is invalid 
php_function_reference.htm
Advertisements