PHP | XMLReader moveToNextAttribute() Function
The XMLReader::moveToNextAttribute() function is an inbuilt function in PHP which is used to move cursor to the next attribute if positioned on an attribute or moves to first attribute if positioned on an element. This function can also be used to check if attributes are there in an element or not.
Syntax:
bool XMLReader::moveToNextAttribute( void )
Parameters: This function doesn’t accept any parameters.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLReader::moveToNextAttribute() function in PHP:
Example 1:
- data.xml
<?xml version= "1.0" encoding= "utf-8" ?>
<div>
<h1> Foo Bar </h1>
</div>
|
- index.php
<?php
$XMLReader = new XMLReader();
$XMLReader ->open( 'data.xml' );
$XMLReader ->read();
$XMLReader ->read();
$XMLReader ->read();
if ( $XMLReader ->moveToNextAttribute()) {
echo "Attribute is there" ;
} else {
echo "No, attributes." ;
}
?>
|
- Output:
No, attributes.
Example 2:
Reference: https://www.php.net/manual/en/xmlreader.movetonextattribute.php
Last Updated :
18 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...