downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SimpleXMLElement::children> <SimpleXMLElement::asXML
Last updated: Fri, 30 Oct 2009

view this page in

SimpleXMLElement::attributes

(PHP 5 >= 5.0.1)

SimpleXMLElement::attributesIdentifies an element's attributes

Beschreibung

SimpleXMLElement attributes ([ string $ns [, bool $is_prefix ]] )

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

Hinweis: SimpleXML definiert für die meisten Methoden Regeln für das Hinzufügen von iterativen Eigenschaften. Diese können weder mit var_dump() oder auf andere Weise angezeigt werden.

Parameter-Liste

ns

An optional namespace for the retrieved attributes

is_prefix

Default to FALSE

Rückgabewerte

Beispiele

Beispiel #1 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";
}
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

name="one"
game="lonely"



SimpleXMLElement::children> <SimpleXMLElement::asXML
Last updated: Fri, 30 Oct 2009
 
add a note add a note User Contributed Notes
SimpleXMLElement::attributes
gillllberg at gmail dot com
04-Nov-2009 11:21
To get an attribute in the node, use node->attributes()->attributeName
skerr at mojavi dot org
10-Dec-2004 07:55
You can also access the node as an array to get attributes:

<?php

$xml
= simplexml_load_file('file.xml');

echo
'Attribute: ' . $xml['attribute'];

?>
inge at elektronaut dot no
26-May-2004 07:53
here's a simple function to get an attribute by name, based on the example

<?php
function findAttribute($object, $attribute) {
  foreach(
$object->attributes() as $a => $b) {
    if (
$a == $attribute) {
     
$return = $b;
    }
  }
  if(
$return) {
    return
$return;
  }
}
?>

SimpleXMLElement::children> <SimpleXMLElement::asXML
Last updated: Fri, 30 Oct 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites