Função attributes() PHP
Definição e Uso
A função attributes() obtém os atributos do elemento SimpleXML.
Esta função fornece os atributos e valores definidos em uma tag XML.
Sintaxe
class SimpleXMLElement { string attributes(ns,is_prefix) }
Parâmetros | Descrição |
---|---|
ns | Opcional. O namespace do atributo a ser pesquisado. |
is_prefix | Opcional. O padrão é false. |
Exemplo
Arquivo XML:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Recordatório</heading> <body type="small" important="low">Não se esqueça da reunião!</body> </note>
Código PHP:
<?php $xml = simplexml_load_file("test.xml"); foreach($xml->body[0]->attributes() as $a => $b) { echo $a,'="',$b,'"'; } ?>
Saída:
type="small" important="low"