PHP | XMLWriter openUri() Function Last Updated : 07 Mar, 2024 Comments Improve Suggest changes Like Article Like Report 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 <?php // Create a new XMLWriter instance $writer = new XMLWriter(); // Create the output stream as PHP $writer->openURI('php://output'); // Start the document $writer->startDocument('1.0', 'UTF-8'); // Start a element $writer->startElement('i'); // Add value to the element $writer->text('GeeksforGeeks'); // End the element $writer->endElement(); // End the document $writer->endDocument(); ?> Output: GeeksforGeeks Example 2: php <?php // Create a new XMLWriter instance $writer = new XMLWriter(); // Create the output stream to a file $writer->openURI('new.xml'); // Start the document $writer->startDocument('1.0', 'UTF-8'); // Start a element $writer->startElement('div'); // Add value to the element $writer->text('Hello World'); // End the element $writer->endElement(); // End the document $writer->endDocument(); ?> Output: This will create a new file called new.xml in the same folder with the following content Comment More infoAdvertise with us Next Article PHP | XMLWriter openUri() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-XML Similar Reads PHP | XMLWriter endPi() Function The XMLWriter::endPi() function is an inbuilt function in PHP which is used to end the current PI which is started using XMLWriter::startPi() function. Processing instructions (PIs) allow documents to contain instructions which are not part of the character data of the document, but are passed throu 2 min read PHP | XMLWriter endDtd() Function The XMLWriter::endDtd() function is an inbuilt function in PHP which is used to end current DTD which is started using XMLWriter::startDtd() function. DTD stands for Document Type Definition which defines the structure and the legal elements and attributes of an XML document. DTD arenât visible in a 1 min read PHP | XMLReader next() Function The XMLReader::next() function is an inbuilt function in PHP which is used to move cursor to next node skipping all subtrees. Another usage of this function is it accepts the name of the node to directly move to the element.Syntax:  bool XMLReader::next( string $localname ) Parameters: This functio 2 min read PHP | xml_parse() Function The xml_parse() function is an inbuilt function in PHP which is used to parse XML document. Syntax: int xml_parse( resource $xml_parser, string $xml_data, bool $is_final ) Parameter: This function accepts three parameters as mentioned above and described below:  $xml_parser: It is required paramet 3 min read PHP XMLWriter endCdata() Function The XMLWriter::endCdata() function is an inbuilt function in PHP which is used to end current CDATA. CDATA is block of text which is not parsed by the parser but are recognized as markup. Syntax: bool XMLWriter::endCdata( void ) Parameters: This function doesnât accept any parameter. Return Value: 2 min read PHP | opendir() Function The opendir() function in PHP is an inbuilt function which is used to open a directory handle. The path of the directory to be opened is sent as a parameter to the opendir() function and it returns a directory handle resource on success, or FALSE on failure. The opendir() function is used to open up 2 min read PHP | XMLWriter setIndentString() Function The XMLWriter::setIndentString() function is an inbuilt function in PHP which is used to set the string which will be used to indent each element/attribute of the resulting xml. Syntax: bool XMLWriter::setIndentString( string $indentString ) Parameters: This function accepts a single parameter $inde 2 min read PHP | XMLWriter setIndent() Function The XMLWriter::setIndent() function is an inbuilt function in PHP which is used to toggle indentation on/off in the XML document which is off by default. Syntax: bool XMLWriter::setIndent( bool $indent ) Parameters: This function accepts a single parameter $indent which holds a boolean stating TRUE 2 min read PHP | XMLReader moveToAttribute() Function The XMLReader::moveToAttribute() function is an inbuilt function in PHP which is used to move cursor to a named attribute. Syntax: bool XMLReader::moveToAttribute( string $name ) Parameters: This function accepts a single parameter $name which holds the name of the attribute. Return Value: This func 2 min read PHP | XMLWriter startCdata() Function The XMLWriter::startCdata() function is an inbuilt function in PHP which is used to start the CDATA. This element then needs to be closed with XMLWriter::endCdata() function. CDATA is a block of text which is not parsed by the parser but are recognized as markup. Syntax: bool XMLWriter::startCdata( 2 min read Like