PHP Parsing: Assets XML
From EVEDev
Sorry, I have been able to preserve the formatting that is present in Editing but not after publishing.
Think I helped you out with formatting a little anyway ;-)
<?php //set up using the php api $file="../xmlcache/*******/**********/char/AssetList.xml.aspx"; /************************************************************************** Please Read:: System: PHP 5.2.5 (SimpleXML builtin), MySQL 5.0. STEP 1: structure of 'asset' table do this FIRST db is'eve_finance' (for example) CREATE TABLE `eve_finance`.`assets` ( `itemID` varchar( 20 ) NOT NULL , `locationID` varchar( 60 ) NOT NULL , `typeID` varchar( 30 ) NOT NULL , `quantity` int( 20 ) NOT NULL , `flag` varchar( 5 ) NOT NULL , `singleton` varchar( 5 ) NOT NULL , `catID` varchar( 30 ) default NULL , `grpID` varchar( 30 ) default NULL , `ID` int( 11 ) NOT NULL auto_increment , PRIMARY KEY ( `ID` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1; STEP 2: You must have access to the following tables from the EVE static database invTypes, invGroups, staStations **********************************************************************/ // open connection $con = mysql_connect($dbHost,$dbUser,$dbPass); if (!$con) { die('Could not connect: ' . mysql_error()); } // select database $db = 'eve_finance'; mysql_select_db($db) or die ("Unable to select database!"); //truncate the assets table $sql="TRUNCATE `assets`"; $result = mysql_query($sql) or die (mysql_error()); $Assets=file_get_contents($file); $inc=0; $sub_inc=0; if (!empty($Assets)) { $AssetsList = array(); $xml = new SimpleXMLElement($Assets); foreach ($xml->result as $result) { foreach ($result->rowset as $rowset) { foreach ($rowset->children() as $gen1) { foreach ($gen1->attributes() as $name => $value) { $AssetsList[$inc] [(string) $name] = (string) $value; if($name=="locationID") {$location_value= $value;} } foreach($gen1 ->children() as $gen2) { foreach($gen2 ->children() as $gen3) { foreach ($gen3->attributes() as $name => $value) { $sub_AssetsList[$sub_inc] [(string) $name] = (string) $value; $sub_AssetsList[$sub_inc] ['locationID'] = $location_value; }//gen3 $sub_inc++; }//gen2 }//gen1 $inc++; }//->children }//rowset }//$xml }//if $str_values=""; //assetslist + subassets load for($y=0; $y <$inc; $y++) { foreach($AssetsList[$y] as $name=>$value) { $str_values .=$value.":"; } list($itemID, $locationID, $typeID, $quantity, $flag, $singleton)=explode(":",$str_values); echo ('<br>'.$itemID.$tab.$locationID.$tab. $typeID.$tab. $quantity.$tab. $flag.$tab. $singleton); $name_list="`itemID`,`locationID`,`typeID`,`quantity`,`flag`,`singleton`"; $sql="INSERT INTO assets ($name_list) VALUES ('$itemID', '$locationID', '$typeID', '$quantity', '$flag', '$singleton')"; $result = mysql_query($sql) or die (mysql_error()); $str_values =""; } for($y=0; $y <$sub_inc; $y++) { foreach($sub_AssetsList[$y] as $name=>$value) { $str_values .=$value.":"; } list($itemID, $locationID, $typeID, $quantity, $flag, $singleton)=explode(":",$str_values); echo ('<br>'.$itemID.$tab.$locationID.$tab. $typeID.$tab. $quantity.$tab. $flag.$tab. $singleton); $name_list="`itemID`,`locationID`,`typeID`,`quantity`,`flag`,`singleton`"; $sql="INSERT INTO assets ($name_list) VALUES ('$itemID', '$locationID', '$typeID', '$quantity', '$flag', '$singleton')"; $result = mysql_query($sql) or die (mysql_error()); $str_values =""; } // replace IDs with text $sql_update="UPDATE assets, invTypes SET assets.grpID = invTypes.groupID WHERE invTypes.typeID = assets.typeID"; $result = mysql_query($sql_update) or die (mysql_error()); $sql_update="UPDATE assets, invGroups SET assets.catID = invGroups.categoryID WHERE invGroups.groupID = assets.grpID"; $result = mysql_query($sql_update) or die (mysql_error()); $sql_update="UPDATE assets, invTypes SET assets.typeID = invTypes.typeName WHERE invTypes.typeID = assets.typeID"; $result = mysql_query($sql_update) or die (mysql_error()); $sql="UPDATE assets, s_staStations SET assets.locationID = staStations.stationName WHERE staStations.stationID = assets.locationID"; $res = mysql_query($sql) or die (mysql_error()); mysql_close($con); ?>

