PHP | DOMDocument normalizeDocument() Function
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 // Create a new document $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Create an element $domElement = $domDocument->createElement('organization', 'GeeksforGeeks'); // Append element to the document $domDocument->appendChild($domElement); // Use normalizeDocument() function // to normalize the document $domDocument->normalizeDocument(); // Create the XML file and display it echo $domDocument->saveXML(); ?> |
<?xml version="1.0" encoding="iso-8859-1"?> <organization>GeeksforGeeks</organization>
Program 2:
<?php // Create a new document $domDocument = new DOMDocument('1.0', 'iso-8859-1'); // Create an element $domElement1 = $domDocument->createElement('organization'); $domElement2 = $domDocument->createElement('name', 'GeeksforGeeks'); $domElement3 = $domDocument->createElement('address', 'Noida'); $domElement4 = $domDocument->createElement('email', 'abc@geeksforgeeks.org'); // Append element to the document $domDocument->appendChild($domElement1); $domElement1->appendChild($domElement2); $domElement1->appendChild($domElement3); $domElement1->appendChild($domElement4); // Use normalizeDocument() function // to normalize the document $domDocument->normalizeDocument(); // Create the XML file and display it echo $domDocument->saveXML(); ?> |
<?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
Recommended Posts:
- PHP | DOMDocument createElement() Function
- PHP | DOMDocument importNode() Function
- PHP | DOMDocument createComment() Function
- PHP | DOMDocument saveXML() Function
- PHP | DOMDocument createCDATASection() Function
- PHP | DOMDocument loadXML() Function
- PHP | DOMDocument createAttribute() Function
- PHP | DOMDocument saveHTMLFile() Function
- PHP | DOMDocument saveHTML() Function
- PHP | DOMDocument getElementsByTagName() Function
- PHP | DOMDocument save() Function
- PHP | DOMDocument loadHTMLFile() Function
- PHP | DOMDocument createElementNS() Function
- PHP | DOMDocument createAttributeNS() Function
- PHP | DOMDocument createTextNode() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



