Função PHP atributos()
Exemplo
Retorne os atributos e valores para o elemento XML <body>:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2014-01-01" type="private">Do
not forget me this weekend!</body>
</note>
XML;
$xml = simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,"<br>";
}
?>
Definição e uso
A função attribute() retorna os atributos e valores de um elemento XML.
Sintaxe
SimpleXMLElement::attributes(ns, prefix)
Valores de parâmetro
Parameter | Description |
---|---|
ns | Optional. Specifies a namespace for the retrieved attributes |
prefix | Optional. Specifies TRUE if ns is a prefix and FALSE if ns is a URI. Default is FALSE |
Detalhes técnicos
Valor de retorno: | Um objeto SimpleXMLElement em caso de sucesso |
---|---|
Versão do PHP: | 5.0+ |
❮ Referência PHP SimpleXML