PHP | XMLReader expand() Function
Last Updated :
20 Mar, 2020
The XMLReader::expand() function is an inbuilt function in PHP which is used to copy the current node and returns the appropriate DOM object.
Syntax:
DOMNode XMLReader::expand( DOMNode $basenode )
Parameters: This function accepts a single parameter $basenode which holds a DOMNode defining the target DOMDocument for the created DOM object.
Return Value: This function returns DOMNode on success or FALSE on failure.
Below examples illustrate the XMLReader::expand() function in PHP:
Example 1:
- data.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< root >
< div > This is a div </ div >
</ root >
|
- index.php
<?php
$XMLReader = new XMLReader();
$XMLReader ->open( 'data.xml' );
$XMLReader ->read();
$element = $XMLReader ->expand();
echo $element ->nodeValue;
?>
|
- Output:
This is a div
Example 2:
- data.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< body >
< h1 style = "color:green; font-size:100px;" >
GeeksforGeeks
</ h1 >
</ body >
|
- index.php
<?php
$XMLReader = new XMLReader();
$XMLReader ->open( 'data.xml' );
$XMLReader ->read();
$element = $XMLReader ->expand();
$DOMDocument = new DOMDocument();
$DOMDocument ->appendChild( $element );
echo $DOMDocument ->saveXML();
|
- Output:
Reference: https://www.php.net/manual/en/xmlreader.expand.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...