PHP | XMLWriter openUri() Function
Last Updated :
07 Mar, 2024
The XMLWriter::openUri() function is an inbuilt function in PHP which is used to create a new XMLWriter using source URI for output. In simple words, this function decides how to output the XML to user, it can be through a browser or directly to a file.
Syntax:
bool XMLWriter::openUri( string $uri )
Parameters:This function accepts a single parameter $uri which holds the uri for output.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLWriter::openUri() function in PHP:
Example 1:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'i' );
$writer ->text( 'GeeksforGeeks' );
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
GeeksforGeeks
Example 2:
<?php
$writer = new XMLWriter();
$writer ->openURI( 'new.xml' );
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->startElement( 'div' );
$writer ->text( 'Hello World' );
$writer ->endElement();
$writer ->endDocument();
?>
|
Output: This will create a new file called new.xml in the same folder with the following content
Share your thoughts in the comments
Please Login to comment...