Forum und email

SimpleXMLElement->addAttribute

(PHP 5 >= 5.1.3)

SimpleXMLElement->addAttribute — Hozzáad egy attribútumot egy SimpleXML elemhez

Leírás

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

Hozzáad egy attribútumot egy SimpleXML elemhez.

Paraméterek

name

A hozzáadandó attribútum neve.

value

Az attribútum értéke.

namespace

Ha meg van adva, a névteret jelöli, amihez a hozzáadandó attribútum tartozik.

Visszatérési értékek

Nincs visszatérítési érték.

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

?>