Re: PHP 5: SimpleXML attributes

From: Date: Wed, 07 Apr 2004 20:26:57 +0000
Subject: Re: PHP 5: SimpleXML attributes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182701@lists.php.net to get a copy of this message
From: "Dan Phiffer" <dan-php@phiffer.org> > I have what I hope to be a simple question about SimpleXML. Is it > possible to get the attributes of a SimpleXML node as an associative array? > > Consider the following: > > <?php > $sxe = simplexml_load_string('<root attr="value"/>'); > print_r($sxe->attributes()); > // Gives: simplexml_element Object ( [0] => value ) > ?> > > Is there some way to find out that 'value' is the attribute called > 'attr'? In other words, can I iterate over SimpleXML attributes without > losing track of what their attribute name is? Or is this a case where I > should switch over to DOM? Have you seen Example 4 here: http://us2.php.net/manual/en/ref.simplexml.php Not sure if that helps or not, though, but it looks like it's already an associative array. ---John Holmes...

« previous php.general (#182701) next »