XMLWriter::setIndent

xmlwriter_set_indent

Toggle indentation on/off

&reftitle.description;

&style.oop;

public `bool` `XMLWriter::setIndent` `bool` `enable`

&style.procedural;

`bool` `xmlwriter_set_indent` `XMLWriter` `writer` `bool` `enable`

Toggles indentation on or off.

&reftitle.parameters;

&xmlwriter.xmlwriter.description;

`enable`

- Whether indentation is enabled.

&reftitle.returnvalues;

&return.success;

&reftitle.changelog;

&Version; | &Description;
&xmlwriter.changelog.writer-param;

&reftitle.examples;

### `XMLWriter::setIndent` and mixed Content

Enabling indentation is not suitable for mixed content, because the indent string is also inserted before inline elements.

    <?php
    $writer = new XMLWriter();
    $writer->openMemory();
    $writer->setIndent(2);
    $writer->startDocument();
    $writer->startElement('p');
    $writer->text('before');
    $writer->writeElement('a', 'element');
    $writer->text('after');
    $writer->endElement();
    $writer->endDocument();
    echo $writer->outputMemory();
    ?>

&example.outputs;

    <?xml version="1.0"?>
    <p>before <a>element</a>
    after</p>

&reftitle.notes;

The indent is reset when an xmlwriter is opened.

&reftitle.seealso;

- `XMLWriter::setIndentString`