PHP | XMLWriter setIndentString() Function
Last Updated :
07 Mar, 2024
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 $indentString which holds the string to be used as indent.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the XMLWriter::setIndentString() function in PHP:
Example 1:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->setIndent(true);
$writer ->setIndentString( '--->' );
$writer ->startElement( 'div' );
$writer ->startElement( 'div' );
$writer ->text( 'Hello World' );
$writer ->endElement();
$writer ->endElement();
$writer ->endDocument();
?>
|
Output: Press Ctrl+U to see the XML
Example 2:
<?php
$writer = new XMLWriter();
$writer ->startDocument( '1.0' , 'UTF-8' );
$writer ->setIndent(true);
$writer ->setIndentString( '--->' );
$writer ->startElement( 'div' );
$writer ->startElement( 'div' );
$writer ->startElement( 'div' );
$writer ->text( 'This is a multi-indented text.' );
$writer ->endElement();
$writer ->endElement();
$writer ->endElement();
$writer ->endDocument();
?>
|
Output:
Share your thoughts in the comments
Please Login to comment...