GPX解析模式和“标准" [英] GPX parsing patterns and "standards"

查看:277
本文介绍了GPX解析模式和“标准"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想继续这篇文章的讨论: GPX架构验证问题.直接讲到这一点,我想问一下人们如何在其软件中解析和使用GPX文件,或者就如何处理GPX文件给我一些建议.

I would like to continue the discussion from this post: GPX Schema validation problems. To go directly to the point, I want to ask how people are parsing and working with GPX files in their software or give me suggestions as to how one should do it.

尽管有人会说,好吧,只需解析trkpt元素并在您的软件中使用它们,对我来说事情就不那么简单了.首先,如以上引用的文章所述,许多gpx产生设备(软件,gps手持设备等)产生的gpx文件不符合正式的GPX架构(元素放置在错误的顺序,值类型的更改,元素名称的更改等).开始解析gpx文件时,我最初的教导是首先检查它们是否针对GPX模式进行验证.其中有很多包含实际的GPS数据(纬度/经度/高程值的序列),但是无论如何都可以设计显示它的格式(尽管很好地被GPX后缀隐藏了).因此,该文件将包含必需的数据,但不符合GPX架构.如何解决这个问题?有什么方法可以使软件接受通用GPX文件作为输入?

Although one may say, well just parse the trkpt elements and use them in your software, the things are not that simple for me. Firstly, as discussed in the cited post above, a lot of the gpx-producing-devices(software, gps-handheld-devices, etc) produce gpx files which do NOT conform to the official GPX schema(elements are laid-out in the wrong order, value types changed, elements' names changed, etc.). My initial taught when starting parsing gpx files, is firstly check if they validate against the GPX schema . There are a lot of them which contain the actual GPS data ( sequence of latitude/longitude/elevation values ) but the format in which it is presented ( although nicely hidden by the GPX suffix) may be designed anyhow. So the file will contain the required data, but will not conform to the GPX schema. How is this problem overcomed ? Is there any way to make the software accept generic GPX files as input ?

其次,我想指出,我对您可能会遇到的各种建议不感兴趣(例如,先对GPX文件进行预处理,然后解析,更改架构等).如果有人知道实践中的工作方式,我会更感兴趣.因此,如果有人在(可能是)商业环境中处理过GPX文件,或者曾经有过处理过的经验,请分享您的想法.

Secondly, I would like to point out I am not interested in various suggestions you may have(e.g. first pre-process the GPX file and then parse it, change your schema, etc.) as to how to solve the problem. I am more interested if someone knows how things are done in practice. So if anyone has or has had any experience with processing GPX files in (possibly) commercial environment please do share your thoughts.

希望我能阐明我的观点.

I hope I made my points clear.

谢谢

Petar

推荐答案

在我的应用程序中,我使用的是常规XML解析器(例如pythons 其他线程中提到的那样,导致验证失败的是GPX标准定义中的<xsd:sequence>.虽然GPX生产设备确实应遵守该标准,但在解析方面(至少与我使用的GPX文件/设备相比)并没有什么大不了的.

In my applications I'm using a normal XML parser (e.g. pythons xml.dom.minidom) I'm just using the tag names to access the information I need. As it was mentioned in the other Thread, the thing that makes validation fail is the <xsd:sequence> in the GPX standard definition. While it's true that GPX producing devices should respect the standard, it's actually not that big of a deal on the parsing side (at least with the GPX Files/Devices I worked on).

如果GPX文件包含其他信息,则它将被删除(除非您选择提取未知的标记名).

If a GPX file contains additional information then it will be dropped (unless you chose to extract the tagnames unknown to you).

如果此方法由于文件无效而失败,则XML或GPX使用不同的标记名称,例如最新信息,除了为此特定用例编写一个特殊的导入程序外,没有其他方法可以读取文件(我没有见过这样的文件,除了损坏的文件,在野外)

If this method fails because the file is not vaild XML or the GPX uses different tag names for e.g. lat lon information there is no other way to read the file than to write a special importer for this specific use case (I have not seen such files, except for corrupted ones, in the wild)

这篇关于GPX解析模式和“标准"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆