XMLWriter::setIndent

xmlwriter_set_indent

(PHP 5 >= 5.1.2, PHP 7, PECL xmlwriter >= 0.1.0)

XMLWriter::setIndent -- xmlwriter_set_indentToggle indentation on/off

Descrierea

Stil obiect-orientat

public XMLWriter::setIndent ( bool $enable ) : bool

Stil procedural

xmlwriter_set_indent ( XMLWriter $writer , bool $enable ) : bool

Toggles indentation on or off.

Parametri

xmlwriter

Numai pentru apelurile procedurale. Resursa XMLWriter care este modificată. Această resursă se obține în urma apelării xmlwriter_open_uri() sau xmlwriter_open_memory ().

enable

Whether indentation is enabled.

Valorile întoarse

Întoarce valoarea true în cazul succesului sau false în cazul eșecului.

Istoricul schimbărilor

Versiune Descriere
8.0.0 writer expects an XMLWriter instance now; previously, a resource was expected.

Exemple

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();
?>

Exemplul de mai sus va afișa:

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

Note

Notă:

The indent is reset when an xmlwriter is opened.

A se vedea și

add a note add a note

User Contributed Notes 1 note

up
7
nemiga at gmail dot com
13 years ago
This param should be used only after openMemory() call:

<?php
$version
= '1.0';
$encoding = 'UTF-8';
$rootName = 'root';

$xml = new XMLWriter();              

$xml->openMemory();
$xml->setIndent(true);
$xml->startDocument($version, $encoding);
$xml->startElement($this->rootName);
// .. add more elements here
$xml->endElement();
echo
$xml->outputMemory();
?>
To Top