(PHP 5 >= 5.1.3)
SimpleXMLElement->addAttribute — Hozzáad egy attribútumot egy SimpleXML elemhez
Hozzáad egy attribútumot egy SimpleXML elemhez.
A hozzáadandó attribútum neve.
Az attribútum értéke.
Ha meg van adva, a névteret jelöli, amihez a hozzáadandó attribútum tartozik.
Nincs visszatérítési érték.
Example#1 Attribútumok és utódok hozzáadása egy SimpleXML elemhez
<?php
$sxe = new SimpleXMLElement($xmlstr); // vagy használd a simplexml_load_string() függvényt
$sxe->addAttribute('type', 'documentary');
$movie = $sxe->addChild('movie');
$movie->addChild('title', 'PHP2: More Parser Stories');
$movie->addChild('plot', 'This is all about the people who make it work.');
$characters = $movie->addChild('characters');
$character = $characters->addChild('character');
$character->addChild('name', 'Mr. Parser');
$character->addChild('actor', 'John Doe');
$rating = $movie->addChild('rating', '5');
$rating->addAttribute('type', 'stars');
echo $sxe->asXML();
?>