Re: Parsing GPX with SimpleXML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, going to respond inline here:



On Wed, Dec 18, 2019 at 1:45 PM Stefan A. <acid24@xxxxxxxxx> wrote:

<gpx version="1.1" xmlns:geotracker="http://my.foo.url">
...
            $attrs = $pt->extensions->children('http://my.foo.url')[0]->attributes();

which yields the expected output

lat: 39.998454   lon: -105.086447    ele: 1568   time: 2019-12-16T10:59:47.000Z    extensions: c: N/A    s: 0
lat: 39.998553   lon: -105.086417    ele: 1577   time: 2019-12-16T11:01:39.000Z    extensions: c: 0.03    s: 1.83
lat: 39.998654   lon: -105.086395    ele: 1572   time: 2019-12-16T11:01:44.000Z    extensions: c: 0.3    s: 2.08

However I don't know if you're able to update the gpx document so another option I tried (with the original gpx content you posted):

Turns out, I won't need to edit the files. They already contain the xml name space in the header, so I just supplied that URL to the children() call and voila, it works as-is.

However this: 

            $attrs = $pt->extensions->children()[0]->attributes();

Throws an error:

 PHP Fatal error:  Uncaught Error: Call to a member function attributes() on null in /home/kirash/GPX/parseGPX1.php:8
Stack trace:
#0 {main}
  thrown in /home/kirash/GPX/parseGPX.php on line 8

Line 8 is that line I quoted above.

So it appears that going with option 1, and supplying the xmlns URL in the children() call solves the problem. I'll take it .... at least until something else breaks.

Thanks again for your help today. That colon in the namespace threw me off.

A

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux