Drezard Posted April 8, 2007 Share Posted April 8, 2007 Okay, I got this stupid XML glitch. It is supposed to run through a loop a few times and each time outputing an XML file (there are currently 3 different ones, so it must run through 3 times), only problem is the loop runs the first time, then it gives me the last two as errors: Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "core/town/items/ shield.const.xml" in C:\Program Files\xampp\htdocs\wintersword\core\town\town.class.php on line 32 Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "core/town/items/ armor.const.xml" in C:\Program Files\xampp\htdocs\wintersword\core\town\town.class.php on line 32 Heres my script: <?php class class_town { function town_store($name) { $idarray = explode(' ', $_SESSION['userinfo']); $id = $idarray[0]; $file = "core/town/shop/".$name.".const.xml"; $xml_town = simplexml_load_file($file); $items = $xml_town->items; $itemsarray = explode(',', $items); $itemssize = count($itemsarray); echo "<table width='100%' border='1'>"; echo "<tr>"; echo "<td><b>Name</b></td>"; echo "<td><b>Cost</b></td>"; echo "<td><b>Type</b></td>"; echo "<td><b>Effect</b></td>"; echo "</tr>"; for ($i = 0; $i < $itemssize; $i++) { $item = $itemsarray[$i]; $file = "core/town/items/".$item.".const.xml"; $xml_item = simplexml_load_file($file); $name = $xml_item->name; $cost = $xml_item->cost; $type = $xml_item->type; $effect = $xml_item->effect; echo "<tr>"; echo "<td><b><a href='town_buyitem.php?item=$name'>$name</a></b></td>"; echo "<td>$cost</td>"; echo "<td>$type</td>"; echo "<td>$effect</td>"; echo "</tr>"; } echo "</table>"; } } ?> And heres my three XML documents: sword.const.xml: <?xml version="1.0"?> <item> <name>Sword</name> <cost>1000</cost> <type>left weap</type> <effect>10</effect> </item> armor.const.xml: <?xml version="1.0"?> <item> <name>Armor</name> <cost>1000</cost> <type>torso</type> <effect>10</effect> </item> shield.const.xml: <?xml version="1.0"?> <item> <name>Shield</name> <cost>1000</cost> <type>right weap</type> <effect>10</effect> </item> So it loads and outputs shield.const.xml but then when it gets to shield.const.xml and armor.const.xml it dies and outputs those 2 errors. - Cheers, Daniel Link to comment https://forums.phpfreaks.com/topic/46083-xml-glitch/ Share on other sites More sharing options...
per1os Posted April 8, 2007 Share Posted April 8, 2007 You have an extra space in $items, try trimming it like so: <?php class class_town { function town_store($name) { $idarray = explode(' ', $_SESSION['userinfo']); $id = $idarray[0]; $file = "core/town/shop/".$name.".const.xml"; $xml_town = simplexml_load_file($file); $items = $xml_town->items; $itemsarray = explode(',', $items); $itemssize = count($itemsarray); echo "<table width='100%' border='1'>"; echo "<tr>"; echo "<td><b>Name</b></td>"; echo "<td><b>Cost</b></td>"; echo "<td><b>Type</b></td>"; echo "<td><b>Effect</b></td>"; echo "</tr>"; for ($i = 0; $i < $itemssize; $i++) { $item = $itemsarray[$i]; $file = "core/town/items/".trim($item).".const.xml"; $xml_item = simplexml_load_file($file); $name = $xml_item->name; $cost = $xml_item->cost; $type = $xml_item->type; $effect = $xml_item->effect; echo "<tr>"; echo "<td><b><a href='town_buyitem.php?item=$name'>$name</a></b></td>"; echo "<td>$cost</td>"; echo "<td>$type</td>"; echo "<td>$effect</td>"; echo "</tr>"; } echo "</table>"; } } ?> see what happens. Link to comment https://forums.phpfreaks.com/topic/46083-xml-glitch/#findComment-223973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.