SimpleXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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) {
        list($k, $v) = each($xml->record->$key->attributes());
        echo "{$k} = {$v}<br>";
        echo "{$key} key / {$value} value<hr>";
    }
}

The results I get are as follows:

0 = BUSINESS_UNIT
column key / C value

0 = BUSINESS_UNIT
column key / 1 value

0 = BUSINESS_UNIT
column key / 2006-01-18 value

0 = BUSINESS_UNIT
column key / CE value

0 = BUSINESS_UNIT
column key / D value

0 = BUSINESS_UNIT
column key / 1 value

0 = BUSINESS_UNIT
column key / 2006-01-18 value

0 = BUSINESS_UNIT
column key / CE value

0 = BUSINESS_UNIT
column key / E value

0 = BUSINESS_UNIT
column key / 5 value

0 = BUSINESS_UNIT
column key / 2006-01-18 value

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux