Click to See Complete Forum and Search --> : SimpleXML


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!

deadpainter
07-06-2010, 08:52 AM
Can no one help out? Is SimpleXML something that isn't used much anymore? Should I try some thing else? Any help would be fanastic. Thanks.

Charles
07-06-2010, 10:21 AM
It's just that this is way more of a PHP question. The good folks on that forum will be better able to help you.

tracknut
07-06-2010, 01:24 PM
You might start with why you want this all in a 2D array. SimpleXML will easily import XML into a nice PHP structure that corresponds with the structure of your XML, and flattening it all out into an array just seems horribly tedious (and given we don't know why it needs to be done, it feels painfully boring to help you do it ;) )

Dave

rubaisport
07-26-2010, 02:40 AM
Can no one help out? Is SimpleXML something that isn't used much anymore? Should I try some thing else? Any help would be fanastic. Thanks.

Im trying to do something similar (a stats generator), but the problem Im having is getting around the colon in the groundspeak tags