You are here: SimpleXML « PHP « IT news, forums, messages
SimpleXML

Posted by Jay Paulson on 01/18/06 23:49

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация