In a browser game I play, the developers have allowed access to a XML file containing town data. I am trying to create a script to basically search and compile that data in various formats that will benefit players. It's been a pain in the butt, but I finally got it to print out town names and player names, however it's not 100% correct. It's assigning towns to the wrong players. I'd appreciate any help with this Here's the code:
FindElement is a function I wrote to skip to the appropriate tag that contains the information I'm seeking. I'm not familiar enough with XMLReader and had a heck of a time finding any examples or tutorials on how to find it. The problem may be there.
Code:
<?php
$ch = curl_init("[URL]http://uk1.illyriad.co.uk/data_downloads/datafile_towns.xml[/URL]");
$fp = fopen("towndata.xml", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
$reader = new XMLReader();
$reader->open("towndata.xml");
echo("<HTML><BODY>");
while ($reader->read()) {
FindElement($reader,"mapx");
$mapx = $reader->value;
FindElement($reader,"mapy");
$mapy = $reader->value;
FindElement($reader,"terraintype");
$terraintype = $reader->value;
FindElement($reader,"playername");
$playername = $reader->value;
FindElement($reader,"playerrace");
$playerrace = $reader->value;
FindElement($reader,"alliancename");
$alliancename = $reader->value;
FindElement($reader,"allianceticker");
$allianceticker = $reader->value;
FindElement($reader,"alliancetaxrate");
$alliancetaxrate = $reader->value;
FindElement($reader,"townname");
$townname = $reader->value;
FindElement($reader,"population");
$population = $reader->value;
FindElement($reader,"iscapitalcity");
$iscapitalcity = $reader->value;
FindElement($reader,"isalliancecapitalcity");
$isalliancecapitalcity = $reader->value;
if($allianceticker == "FDU")
{
echo "Town Name: ", $townname, "<BR>";
echo "Player Name: ", $playername, "<BR>";
}
}
echo("</BODY></HTML>");
function FindElement(&$readerobject, $name)
{
while($readerobject->name != $name)
{
if(!$readerobject->read()) break;
}
if($readerobject->name == $name)
{$readerobject->read();
return 1;
}
else return 0;
}
?>
FindElement is a function I wrote to skip to the appropriate tag that contains the information I'm seeking. I'm not familiar enough with XMLReader and had a heck of a time finding any examples or tutorials on how to find it. The problem may be there.