PHP attributes()Funciones
Manual de referencia de PHP SimpleXML
Ejemplos
Devuelve los atributos y valores del elemento body del XML:
<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body date="2013-01-01" type="private">Don't forget me this weekend!</body>
</note>
XML;
$xml=simplexml_load_string($note);
foreach($xml->body[0]->attributes() as $a => $b)
{
echo $a,'="',$b,""<br>";
}
?>
Ejecutar ejemplo »
Definición y uso
La función attributes() devuelve los atributos y valores de las etiquetas XML.
Sintaxis
attributes(ns,is_prefix);
| Parámetros | Descripción |
|---|---|
| ns | Opcional. Especifica el espacio de nombres de los atributos que se van a recuperar. |
| is_prefix | Opcional. Especifica un valor booleano. Sinses un prefijo, entonces TRUE; sinses un URI, entonces FALSE. El valor predeterminado es FALSE. |
Detalles técnicos
| Valor de retorno: | Devuelve un objeto SimpleXMLElement si tiene éxito. |
|---|---|
| Versión de PHP: | 5.0.1+ |
Manual de referencia de PHP SimpleXML Otras extensiones