XMLWriter::endDocument

xmlwriter_end_document

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

XMLWriter::endDocument -- xmlwriter_end_documentTermine le document courant

Description

Style orienté objet

public XMLWriter::endDocument(): bool

Style procédural

xmlwriter_end_document(XMLWriter $writer): bool

Termine le document courant.

Liste de paramètres

writer

Uniquement pour les appels procéduraux. L'instance XMLWriter qui est modifiée. Cet objet provient d'un appel à xmlwriter_open_uri() ou xmlwriter_open_memory().

Valeurs de retour

Cette fonction retourne true en cas de succès ou false si une erreur survient.

Historique

Version Description
8.0.0 writer attend une instance de XMLWriter désormais; auparavant, une resource était attendu.

Voir aussi

add a note

User Contributed Notes 1 note

up
0
Sbastien
2 years ago
XMLWriter::endDocument() closes properly all remaining elements not yet closed.

Without XMLWriter::endDocument() :

<?php
$xml
= new XMLWriter();
$xml->openUri('php://stdout');
$xml->startDocument();
$xml->startElement('a');
$xml->startElement('b');
$xml->startElement('c');
$xml->startAttribute('foo');
exit;

/*
Outputs :
<?xml version="1.0"?>
<a><b><c foo="
*/
?>

With XMLWriter::endDocument() :

<?php
$xml
= new XMLWriter();
$xml->openUri('php://stdout');
$xml->startDocument();
$xml->startElement('a');
$xml->startElement('b');
$xml->startElement('c');
$xml->startAttribute('foo');
$xml->endDocument();
exit;

/*
Outputs :
<?xml version="1.0"?>
<a><b><c foo=""/></b></a>
*/
?>
To Top