JavaScript Editor Javascript debugger     Website design 


SimpleXMLElement->attributes()

Identifies an element's attributes ()

SimpleXMLElement {
  SimpleXMLElement attributes(string ns,
                              bool is_prefix);

}

This function provides the attributes and values defined within an xml tag.

Note:

SimpleXML has made a rule of adding iterative properties to most methods. They cannot be viewed using var_dump() or anything else which can examine objects.

Parameters

ns

An optional namespace for the retrieved attributes

is_prefix

Default to FALSE

Return Values

Examples

Example 2251. Interpret an XML string

<?php
$string
= <<<XML
<a xmlns:b>
<foo name="one" game="lonely">1</foo>
</a>
XML;

$xml = simplexml_load_string($string);
foreach(
$xml->foo[0]->attributes() as $a => $b) {
   echo
$a,'="',$b,"\"\n";
}
?>

The above example will output:

name="one"
game="lonely"