load xml with php

fahmiweb

New Member
I have XML file\[code\]<shop><categories><category id="-2147483638" parent="0" name="Dia"/><category id="-2147483637" parent="0" name="Stri"/><categories><parameters><parameter id="6" name="Druh" typ="ENUM" systemid=""><enumValue valueId="5" value="http://stackoverflow.com/questions/13859431/Be"/><enumValue valueId="6" value="http://stackoverflow.com/questions/13859431/Zi"/><enumValue valueId="7" value="http://stackoverflow.com/questions/13859431/Po"/><enumValue valueId="8" value="http://stackoverflow.com/questions/13859431/Di"/><enumValue valueId="9" value="http://stackoverflow.com/questions/13859431/Pr"/><enumValue valueId="10" value="http://stackoverflow.com/questions/13859431/Ma"/><enumValue valueId="11" value="http://stackoverflow.com/questions/13859431/Ma"/><enumValue valueId="12" value="http://stackoverflow.com/questions/13859431/Gr"/><enumValue valueId="13" value="http://stackoverflow.com/questions/13859431/Ak"/><enumValue valueId="14" value="http://stackoverflow.com/questions/13859431/Ru"/><enumValue valueId="15" value="http://stackoverflow.com/questions/13859431/Za"/><enumValue valueId="16" value="http://stackoverflow.com/questions/13859431/Kr"/><enumValue valueId="17" value="http://stackoverflow.com/questions/13859431/Pe"/></parameter><parameter id="9" name="?perk" typ="ENUM" systemid="s9"><enumValue valueId="4" value="http://stackoverflow.com/questions/13859431/Male"/> <enumValue valueId="5" value="http://stackoverflow.com/questions/13859431/Female"/><enumValue valueId="6" value="http://stackoverflow.com/questions/13859431/Unisex"/></parameter></parameters></shop>\[/code\]and PHP code for reading the xml:\[code\]<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>SET NAMES 'utf8'; TRUNCATE TABLE ocppoption;truncate table ocppoption_description ;<?$request_url = "http://...xml"; // $xml = simplexml_load_file($request_url) or die("error"); $language=2;foreach($xml->parameters->parameter as $key) { echo "\n\r<br/><br/>insert into option values (".$key['id'].", 'select' ,1);"; echo "\n\r<br/>insert into option_description values (".$key['id'].", 1,'".$key['name']."');";if (!isset($j)) {$j=1;} $i=0; $k=1; $i=$j; foreach($key->attributes() as $enum => $val) { echo "\n\n\r<br/><br/>insert into option_value values ( ".$i++.",".$key['id']." ,'' , ".$k++." );"; $j=$i;}}\[/code\]I have output:\[code\] insert into option values ( 6 , 'select' ,1 ); insert into option_description values ( 6 , 1 ,'Druh' ); insert into option_value values ( 1 ,6 ,'' , 1 ); insert into option_value values ( 2 ,6 ,'' , 2 ); insert into option_value values ( 3 ,6 ,'' , 3 ); \[/code\]but if I want to load values from tag \[code\]<enumValue valueId="4" value="http://stackoverflow.com/questions/13859431/Male"/>. \[/code\]so I want output like insert into option_value values ( 4, 6 ,'' , 3 );It didnt work correctly. Can you please help me? I need to have output 4, Male... how can I get this values from xml?
 
Back
Top