Re: SimpleXML

From: Date: Wed, 18 Jan 2006 22:52:14 +0000
Subject: Re: SimpleXML
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-228789@lists.php.net to get a copy of this message
On Wed, January 18, 2006 3:49 pm, Jay Paulson wrote: > I'm a noob when it comes to parsing an XML file. I have a really > simple > file that I'm getting back from a SOAP service that I need to parse. > I > figure SimpleXML would be great! However, I'm having problems getting > the > name attribute for each column element. The XML is below along with > the > code I'm using to parse it. > > $xml = <<<XML > <resultSet recordCount="3" columnCount="4"> > <record> > <column name="BUSINESS_UNIT">CE</column> > <column name="ATTENDANCE">C</column> > <column name="COUNT(A.EMPLID)">1</column> > <column name="TO_CHAR(SYSDATE,YYYY-MM-DD)">2006-01-18</column> > </record> > <record> > <column name="BUSINESS_UNIT">CE</column> > <column name="ATTENDANCE">D</column> > <column name="COUNT(A.EMPLID)">1</column> > <column name="TO_CHAR(SYSDATE,YYYY-MM-DD)">2006-01-18</column> > </record> > <record> > <column name="BUSINESS_UNIT">CE</column> > <column name="ATTENDANCE">E</column> > <column name="COUNT(A.EMPLID)">5</column> > <column name="TO_CHAR(SYSDATE,YYYY-MM-DD)">2006-01-18</column> > </record> > </resultSet> > XML; > > $xml = simplexml_load_string($xml); > print_r($xml); ////////> foreach ($xml->record as $record) { foreach ($xml->record as $key => $record){ echo $key, ": <br />\n"; > list($k, $v) = each($xml->record->$key->attributes()); > echo "{$k} = {$v}<br>"; > echo "{$key} key / {$value} value<hr>"; > } > } -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#228789) next »