função PHP addAttribute ()
Manual do PHP SimpleXML Referência
Exemplos
elemento raiz eo elemento corpo para adicionar um atributo:
<?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","2013-01-01");
echo $xml->asXML();
?>
$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","2013-01-01");
echo $xml->asXML();
?>
Correndo instância »
Definição e Uso
função addAttribute () para adicionar um atributo ao elemento SimpleXML.
gramática
addAttribute( name,value,ns );
参数 | 描述 |
---|---|
name | 必需。规定要添加的属性的名称。 |
value | 可选。规定属性的值。 |
ns | 可选。规定属性的命名空间。 |
detalhes técnicos
retorna: | Nenhum valor de retorno. |
---|---|
versão do PHP: | 5.1.3+ |
Manual do PHP SimpleXML Referência