PHP | XMLWriter endDocument() Function
Last Updated :
07 Mar, 2024
The XMLWriter::endDocument() function is an inbuilt function in PHP which is used to end current document.
Syntax:
bool XMLWriter::endDocument( void )
Parameters: This function doesn’t accept any parameter.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLWriter::endDocument() function in PHP:
Example 1:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'div' );
$writer ->text( 'GeeksforGeeks' );
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
<?xml version="1.0" encoding="UTF-8"?>
<div>GeeksforGeeks</div>
Example 2:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'h1' );
$writer ->startAttribute( 'style' );
$writer ->text( 'color:green;font-size:80px;' );
$writer ->endAttribute();
$writer ->text( 'GeeksforGeeks' );
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
<?xml version="1.0" encoding="UTF-8"?>
<h1 style="color:green;font-size:80px;">GeeksforGeeks</h1>
Share your thoughts in the comments
Please Login to comment...