PHP | DOMDocument normalizeDocument() Function
Last Updated :
30 Aug, 2019
The DOMDocument::normalizeDocument() function is an inbuilt function in PHP which is used to normalize the document. This function is used to convert the document into the normal form if you saved and then loaded the document.
Syntax:
void DOMDocument::normalizeDocument( void )
Parameters: This function does not accept any parameters.
Return Value: This function does not return any value.
Below programs illustrate the DOMDocument::normalizeDocument() function in PHP:
Program 1:
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domElement = $domDocument ->createElement( 'organization' , 'GeeksforGeeks' );
$domDocument ->appendChild( $domElement );
$domDocument ->normalizeDocument();
echo $domDocument ->saveXML();
?>
|
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<organization>GeeksforGeeks</organization>
Program 2:
<?php
$domDocument = new DOMDocument( '1.0' , 'iso-8859-1' );
$domElement1 = $domDocument ->createElement( 'organization' );
$domElement2 = $domDocument ->createElement( 'name' , 'GeeksforGeeks' );
$domElement3 = $domDocument ->createElement( 'address' , 'Noida' );
$domElement4 = $domDocument ->createElement( 'email' , 'abc@geeksforgeeks.org' );
$domDocument ->appendChild( $domElement1 );
$domElement1 ->appendChild( $domElement2 );
$domElement1 ->appendChild( $domElement3 );
$domElement1 ->appendChild( $domElement4 );
$domDocument ->normalizeDocument();
echo $domDocument ->saveXML();
?>
|
Output:
<?xml version="1.0" encoding="iso-8859-1"?>
<organization>
<name>GeeksforGeeks</name>
<address>Noida</address>
<email>abc@geeksforgeeks.org</email>
</organization>
Reference: https://www.php.net/manual/en/domdocument.normalizedocument.php
Share your thoughts in the comments
Please Login to comment...