XMLWriter::setIndent
xmlwriter_set_indent
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL xmlwriter >= 0.1.0)
XMLWriter::setIndent -- xmlwriter_set_indent — Toggle indentation on/off
Descrição
Estilo orientado a objetos
Estilo procedural
Toggles indentation on or off.
Parâmetros
-
writer
Apenas para chamadas procedurais. A instância de XMLWriter que está sendo modificada. Este objeto é retornado de uma chamada a xmlwriter_open_uri() ou xmlwriter_open_memory().
enable
-
Whether indentation is enabled.
Registro de Alterações
Versão | Descrição |
---|---|
8.0.0 |
O parâmetro writer agora espera uma instância de XMLWriter;
anteriormente, um resource era esperado.
|
Exemplos
Example #1 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();
?>
O exemplo acima produzirá:
<?xml version="1.0"?> <p>before <a>element</a> after</p>
Notas
Note:
The indent is reset when an xmlwriter is opened.