By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Need help with PHP-XML parser

P: 2

I am trying to make a xml-parser, but now I am stuck....

This is my xml:

[PHP]<Emission type="CO2">249</Emission>
<EUEconomy type="city">14.5</EUEconomy>
<EUEconomy type="road">8</EUEconomy>
<EUEconomy type="combined">10.4</EUEconomy>[/PHP]

..and now Im having problems with EUEconomies.. Cant get those values out of there, only first data and that one three times. What should I do so at I can get tose values out????

This is part of my PHP:

[PHP]if ($state=="EMISSION") { $userdata[$usercount]["Emission"] = $data;}
if ($state=="ACCELERATION") { $userdata[$usercount]["Acceleration"] = $data;}
if ($state=="MAXSPEED") { $userdata[$usercount]["MaxSpeed"] = $data;}
if ($state=="EUECONOMY") { $userdata[$usercount]["EUEconomy"] = $data;}
if ($state=="EUECONOMY") { $userdata[$usercount]["EUEconomy1"] = $data;}
if ($state=="EUECONOMY") { $userdata[$usercount]["EUEconomy2"] = $data;}[/PHP]


[PHP]if (!($xml_parser = xml_parser_create())) die("Couldn't create parser.");
xml_set_element_handler( $xml_parser, "startElementHandler", "endElementHandler");
xml_set_character_data_handler( $xml_parser, "characterDataHandler");

//while( $data = fread($fp, 16384)){
while( $data = fread($fp, 8192)){
if(!xml_parse($xml_parser, $data, feof($fp))) {

for ($i=0;$i<$usercount; $i++)[/PHP]


[PHP]$Emission = $userdata[$i]["Emission"];
$Acceleration = $userdata[$i]["Acceleration"];
$MaxSpeed = $userdata[$i]["MaxSpeed"];
$EUEconomy1 = $userdata[$i]["EUEconomy1"];[/PHP]

Thanks for advance
Mar 4 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.