XMLWriter::writeAttribute
PHP function
Edit on GitHub ✎
(PHP 5 >= 5.1.2, PHP 7, PHP 8, PECL xmlwriter >= 0.1.0)
Write full attribute
Description
Oop
XMLWriter::writeAttribute(string $name, string $value): bool
Procedural
xmlwriter_write_attribute(XMLWriter $writer, string $name, string $value): bool
Writes a full attribute.
Parameters
nameThe name of the attribute.
valueThe value of the attribute.
Return Values
Success
Changelog
| Version | Description |
|---|
Examples
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
<?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();
?>The above example will output:
output
bool(false)
<element attr1="0"><subelem>0</subelem></element>See Also
XMLWriter::writeAttributeNsXMLWriter::startAttributeXMLWriter::startAttributeNsXMLWriter::endAttribute