XMLWriter::writeAttribute

xmlwriter_write_attribute

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

XMLWriter::writeAttribute -- xmlwriter_write_attributeEscribe un atributo completo

Descripción

Estilo orientado a objetos

public XMLWriter::writeAttribute(string $name, string $value): bool

Estilo por procedimientos

xmlwriter_write_attribute(XMLWriter $writer, string $name, string $value): bool

Escribe un atributo completo.

Parámetros

xmlwriter

Sólo para llamadas por procedimientos. El resource XMLWriter que está siendo modificado. Este recurso proviene de una llamada a xmlwriter_open_uri() o xmlwriter_open_memory().

name

El nombre del atributo.

value

El valor del atributo.

Valores devueltos

Devuelve true en caso de éxito o false en caso de error.

Historial de cambios

Versión Descripción
8.0.0 writer expects an XMLWriter instance now; previously, a resource was expected.

Ejemplos

Ejemplo #1 Intermixing Sub-elements and Attributes

If writing sub-elements and attributes is intermixed, any attempt to write attributes after the first sub-element will fail and return false.

<?php
$xml
= new XMLWriter();
$xml->openMemory();

$xml->startElement('element');
$xml->writeAttribute('attr1', '0');
$xml->writeElement('subelem', '0');
var_dump($xml->writeAttribute('attr2', '0'));
$xml->endElement();

echo
$xml->flush();
?>

El resultado del ejemplo sería:

bool(false)
<element attr1="0"><subelem>0</subelem></element>

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top