SimpleXMLElement->addAttribute

(no version information, might be only in CVS)

SimpleXMLElement->addAttribute --  SimpleXML elemhez attribútumot ad.

Leírás

void SimpleXMLElement->addAttribute ( string name, string value [, string namespace] )

SimpleXML elemhez attribútumot ad.

Paraméterek

name

A hozzáadandó attribútum neve.

value

Az attribútum értéke

namespace

Ha megadott, a névtér amihez az attribútum tartozik.

Példák

Példa 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();

?>

Lásd még

SimpleXMLElement->addChild