attributes ( $ns, $is_prefix )

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

Access

public

Parameters

Parameter

Type

Required

Description

$ns

string

Optional

An optional namespace for the retrieved attributes

$is_prefix

boolean

Optional

Default to FALSE

Returns

Type

Description

SimpleXMLElement

Returns a SimpleXMLElement object that can be iterated over to loop through the attributes on the tag.

Returns NULL if called on a SimpleXMLElement object that already represents an attribute and not a tag.

Examples

Interpret an XML string

$string = <<<XML
<a>
 <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";
}
Result:
name="one"
game="lonely"

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback