Re: Parsing GPX with SimpleXML
| From: | Ashley M. Kirchner | Date: | Thu, 19 Dec 2019 01:25:09 +0000 |
| Subject: | Re: Parsing GPX with SimpleXML | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326973@lists.php.net to get a copy of this message | ||
Ok, going to respond inline here:
On Wed, Dec 18, 2019 at 1:45 PM Stefan A. <acid24@gmail.com> wrote:
>
> <gpx version="1.1" xmlns:geotracker="Ù…[aæ#
> Çï¦ðf ‡?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