gpx 文件的 php simple_xml xpath 问题

发布于 2024-09-14 10:31:37 字数 233 浏览 0 评论 0原文

我尝试从 gpx 文件(GPS XML)获取经纬度。 当我这样做时(片段): $res = $xml->xpath('//*'); 我得到了返回的完整内容。 当我尝试像这样缩小范围时: $res = $xml->xpath('//rte'); 我什么也没得到: array(0) { }。 即使标签存在。 实际上,无论我在 // other then * 之后尝试填写什么,它都不会返回任何内容。已经尝试了几个小时了...

I try to get the lat and lon's from a gpx file (GPS XML).
When I do (snippet): $res = $xml->xpath('//*');
I get the full content returned.
When I try to narrow down like this: $res = $xml->xpath('//rte');
I get nothing: array(0) { }.
Even when the tag(s) exists.
Actually whatever I try to fill in after // other then * it returns nothing. Have been trying for hours...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔嚣张 2024-09-21 10:31:37

您应该使用正确的命名空间(也许“http://www.topografix.com/GPX/1 /1"?) 在你的节点测试中。

例如:

$xml = simplexml_load_file($URI);
$xml->registerXPathNamespace('gpx', 'http://www.topografix.com/GPX/1/1');
$res = $xml->xpath('//gpx:rte');

You should use the correct namespace (Maybe "http://www.topografix.com/GPX/1/1"?) in your node test.

As example:

$xml = simplexml_load_file($URI);
$xml->registerXPathNamespace('gpx', 'http://www.topografix.com/GPX/1/1');
$res = $xml->xpath('//gpx:rte');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文