deadpainter
07-05-2010, 04:03 PM
I was wondering if someone would be able to assist with a website I'm working on. I'm very, very new to PHP and XML and programming in general. I'm hoping someone may be able to show me quite quickly what will probably take quite some time on my own to figure out.
Basically, I'm tryin to use PHP and SimpleXML to load a large amount of data into a 2-dimensional array. Anyone who is familiar with geocaching, will be familiar with the example below:
<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns:xsi="http://www" xmlns:xsd="http://www" version="1.0" creator="Creator" xsi:schemaLocation="http://www" xmlns="http://www">
<name>Name</name>
<desc>Desciption</desc>
<wpt lat="99.99999" lon="00.00000">
<time>Time</time>
<name>Name</name>
<desc>Desciption</desc>
<groundspeak:cache id="0000000" available="True" archived="False" xmlns:stuff">
<groundspeak:name>Groundspeak Name</groundspeak:name>
<groundspeak:placed_by>Groundspeak Placed By</groundspeak:placed_by>
<groundspeak:owner id="000000">Owner ID</groundspeak:owner>
</groundspeak:cache>
</wpt>
<wpt lat="99.99999" lon="00.00000">
<time>Time</time>
<name>Name</name>
<desc>Desciption</desc>
<groundspeak:cache id="0000000" available="True" archived="False" xmlns:stuff">
<groundspeak:name>Groundspeak Name</groundspeak:name>
<groundspeak:placed_by>Groundspeak Placed By</groundspeak:placed_by>
<groundspeak:owner id="000000">Owner ID</groundspeak:owner>
</groundspeak:cache>
</wpt>
</gpx>
I've removed a large bit of the file to simplify it, but you can definitely understand what I'm after from what's left.
I would like to load the <wpt> data and the <groundspeak> data into the array. The <gpx> data at the start of the file is not needed. So in the end I would end up with something like:
MyArray[0,0] = Time1
MyArray[0,1] = Name1
MyArray[0,2] = Desc1
MyArray[0,3] = Groundspeak Name
MyArray[0,4] = Groundspeak Placed By
MyArray[0,5] = Owner ID
MyArray[1,0] = Time2
MyArray[1,1] = Name2
MyArray[1,2] = Desc2
MyArray[1,3] = Groundspeak Name
MyArray[1,4] = Groundspeak Placed By
MyArray[1,5] = Owner ID
Hope this makes sense. I've tried a few different scenarios but can't seem to some up with a way for this to work. I think my real problem comes with ignoring the <gpx> data, keeping the <wpt> data and then trying to get the <groundspeak:> data, due to it being another child node.
Any help would be great. Pointing me in the right direction and/or some examples would be greatly appreciated.
Let me know if you have any questions, I'll do my best answer them.
Thanks!
Basically, I'm tryin to use PHP and SimpleXML to load a large amount of data into a 2-dimensional array. Anyone who is familiar with geocaching, will be familiar with the example below:
<?xml version="1.0" encoding="utf-8"?>
<gpx xmlns:xsi="http://www" xmlns:xsd="http://www" version="1.0" creator="Creator" xsi:schemaLocation="http://www" xmlns="http://www">
<name>Name</name>
<desc>Desciption</desc>
<wpt lat="99.99999" lon="00.00000">
<time>Time</time>
<name>Name</name>
<desc>Desciption</desc>
<groundspeak:cache id="0000000" available="True" archived="False" xmlns:stuff">
<groundspeak:name>Groundspeak Name</groundspeak:name>
<groundspeak:placed_by>Groundspeak Placed By</groundspeak:placed_by>
<groundspeak:owner id="000000">Owner ID</groundspeak:owner>
</groundspeak:cache>
</wpt>
<wpt lat="99.99999" lon="00.00000">
<time>Time</time>
<name>Name</name>
<desc>Desciption</desc>
<groundspeak:cache id="0000000" available="True" archived="False" xmlns:stuff">
<groundspeak:name>Groundspeak Name</groundspeak:name>
<groundspeak:placed_by>Groundspeak Placed By</groundspeak:placed_by>
<groundspeak:owner id="000000">Owner ID</groundspeak:owner>
</groundspeak:cache>
</wpt>
</gpx>
I've removed a large bit of the file to simplify it, but you can definitely understand what I'm after from what's left.
I would like to load the <wpt> data and the <groundspeak> data into the array. The <gpx> data at the start of the file is not needed. So in the end I would end up with something like:
MyArray[0,0] = Time1
MyArray[0,1] = Name1
MyArray[0,2] = Desc1
MyArray[0,3] = Groundspeak Name
MyArray[0,4] = Groundspeak Placed By
MyArray[0,5] = Owner ID
MyArray[1,0] = Time2
MyArray[1,1] = Name2
MyArray[1,2] = Desc2
MyArray[1,3] = Groundspeak Name
MyArray[1,4] = Groundspeak Placed By
MyArray[1,5] = Owner ID
Hope this makes sense. I've tried a few different scenarios but can't seem to some up with a way for this to work. I think my real problem comes with ignoring the <gpx> data, keeping the <wpt> data and then trying to get the <groundspeak:> data, due to it being another child node.
Any help would be great. Pointing me in the right direction and/or some examples would be greatly appreciated.
Let me know if you have any questions, I'll do my best answer them.
Thanks!