Esempio
Aggiungere un attributo all'elemento radice (<note>) e al <body> elemento:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;
$xml = new SimpleXMLElement($note);
$xml->addAttribute("type","private");
$xml->body->addAttribute("date","2014-01-01");
echo $xml->asXML();
?>
Esempio Run » Definizione e l'utilizzo
addAttribute() funzione aggiunge un attributo all'elemento SimpleXML.
Sintassi
addAttribute( name,value,ns );
Parametro | Descrizione |
---|---|
name | Necessario. Specifica il nome dell'attributo da aggiungere |
value | Opzionale. Specifica il valore dell'attributo |
ns | Opzionale. Specifica uno spazio dei nomi per l'attributo |
Dettagli tecnici
Valore di ritorno: | Nessun valore viene restituito |
---|---|
Versione PHP: | 5.1.3+ |
<PHP SimpleXML di riferimento