GoLang SimpleXMLElement::attributes

request it (327)
GoLang replacement for PHP's SimpleXMLElement::attributes [edit | history]



Do you know a GoLang replacement for PHP's SimpleXMLElement::attributes? Write it!

PHP SimpleXMLElement::attributes

PHP original manual for SimpleXMLElement::attributes [ show | php.net ]

SimpleXMLElement::attributes

(PHP 5, PHP 7)

SimpleXMLElement::attributesIdentifies an element's attributes

Description

public SimpleXMLElement SimpleXMLElement::attributes ([ string $ns = NULL [, bool $is_prefix = FALSE ]] )

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

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

Example #1 Interpret an XML string

<?php
$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";
}
?>

The above example will output:

name="one"
game="lonely"