GPX Schema 验证问题 [英] GPX Schema validation problems

查看:40
本文介绍了GPX Schema 验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个主要使用 GPX 文件作为输入数据的应用程序.鉴于 gpx 文件应该由 gpx 模式定义(定义如下:http://www.topografix.com/gpx.asp),我教的第一件事是对我的应用程序合理地做的是根据模式验证输入文件(当然要记住不同的版本).到现在为止还挺好.对于我正在测试的初始文件,一切都很完美.但是,有时我使用 .gpx 文件,结果证明这些文件对相关的 gpx 架构无效.所以,我试图用其他类似的工具导入它们,奇怪的是,没有返回错误并且文件被完美解析.所以,最合乎逻辑的结论是我的代码有问题.但是,经过彻底调查后,我的代码完全没问题,目前没有问题.这甚至通过 topografix.com ( http://www.topografix.com/gpx_validation.asp ) ,它再次得出结论该文件无效.

I am building an application that works primarily with GPX files as the input data. Given the fact that gpx files are supposed to be defined by the gpx schema (as defined here: http://www.topografix.com/gpx.asp), the first thing that I taught is reasonable to do with my application was to validate the input file against the schema(bearing in mind the different versions of course). So far so good. For the initial files I was testing, everything was perfect. However, sometimes I use .gpx files which turn out to be invalid against the relevant gpx schema. So, I was trying to import them with other similar tools and strangely, no error was returned and the file was parsed perfectly. So, the most logical conclusion is that there is a problem with my code. However, after a thorough investigation, my code was totally fine and no problems with it were at present. This was even verified by the suggested validation technique from topografix.com ( http://www.topografix.com/gpx_validation.asp ) , and it again concluded the file is invalid.

所以,事实证明有一些 GPS 设备/GPS 记录系统/等.生成不符合官方 GPX 架构的 .gpx 文件.这个结论让我提出一个问题:为什么?我真的不明白它背后的想法.此外,对于我发现的大多数无效文件,问题不是可以被视为附加功能的问题,而是类似于某些元素的孩子没有遵循正确的顺序,我认为这完全是愚蠢的.

So, it turns out that there are some GPS devices/GPS recording systems/etc. which produce .gpx files without conforming to the official GPX schema. This conclusions leads me to ask the question: WHY ? I seriously do not understand the idea behind it. Furthermore, with most of the invalid files I have found, the problem is not something that may be regarded as an additional feature but is something like not following the right order with some elements' children which I consider to be totally stupid.

这让我想问你两个问题.首先,如果有人能向我解释为什么我在网上找到的许多 GPX 文件不符合官方 GPX 架构,我会很高兴.其次,我想问一下,如果你要解析GPX文件,你是如何处理这个问题的.毕竟,跟踪点无论如何都会在文件中,所以我是否只需忽略 XML 模式验证并继续直接解析?但话又说回来,如果属性名称拼写错误,我的系统就会崩溃.非常感谢有关您如何处理解析 GPS 文件的任何信息.

This leads me to ask two questions to you. Firstly, I would be happy if someone can explain to me why is that a lot of the GPX files that I found on the web do not conform to the official GPX schema. Secondly, I would like to ask you how do you deal with this problem if you are to parse GPX files. After all, the track points will be in the file anyway, so do I simply have to ignore XML schema validation and proceed with direct parsing ? But then again, if there is a misspelled attribute name, my system would crash. Any information on how do you deal with parsing GPS files will be very much appreciated.

感谢您的时间和帮助.

问候,

皮塔尔

我发布了一个新线程:GPX 解析模式和标准" 我在问人们实际上是如何解析 GPX 文件的.如果您有任何想法,请在此处发布您的答案.

I have posted a new thread: GPX parsing patterns and "standards" where I am asking how people are actually parsing GPX files in practice. If you have an idea please post your answer there.

推荐答案

架构作者选择使用 而不是 >.XSD 序列是特定于订单的.

The schema authors chose to use <xs:sequence> instead of <xs:all>. XSD sequences are order-specific.

拼写错误的属性名称将是无效输入.你必须优雅地验证和失败.计算机不擅长处理歧义.

A misspelled attribute name would be invalid input. You have to validate and fail gracefully. Computers do not do well with ambiguity.

希望有帮助...

更新:

对不起,请允许我详细说明.问题是由模式的作者和 GPX 输出作者(各种软件包和设备的)造成的.

Sorry, allow me to elaborate then. The problem was created by the authors of the schema AND the GPX output authors (of the various software packages and devices).

基本上,如果一个人可以查看数据并理解其含义,那么软件实现者就有责任创建灵活的验证,以便程序可用.

Basically, if a person can look at piece of data and understand what it means, the onus is on the software implementer to create flexible validation so that the program is usable.

例如,假设您有一个输入字段,您应该输入美元金额,而用户输入$.05",则该软件应该足够智能以识别为 5 美分,并且足够智能以识别前面有个空格没用.

For example, suppose you have a input field that you're supposed to enter a dollar amount, and the user enters " $.05", the software should be smart enough to recognize that as 5 cents and smart enough to recognize that there's a space in front and it's useless.

这同样适用于来自设备的文件.是的,问题是他们造成的.是的,当格式有一个非常好的严格定义时,必须将设备的输出视为用户输入是荒谬的.但这就是您目前面临的问题.归根结底,没有人关心您必须克服哪些技术挑战才能使其发挥作用.他们只关心它有用吗"和这对我有多大用处".

The same applies for files from a device. Yes, the problem was created by them. Yes, it's ridiculous to have to treat output from a device as user input when there's a perfectly good strict definition for the format. But that's the problem that you're currently faced with. And at the end of the day, no one cares what technical challenges you had to overcome to make it work. All they care about is "does it work" and "how useful is this for me".

因此,如果您发现字段乱序,但其他所有必需的数据都存在,请重新排列字段以使其通过验证.使您的导入灵活.如果缺少空白,请使用警告消息填充数据空白.但是,让它发挥作用.

So, if you see that the fields are out of order, but otherwise all of the required data is present, rearrange the fields so they pass validation. Make your import flexible. Fill in gaps in data with a warning message, if gaps are missing. But, make it work.

除了在针对 XSD 验证数据之前尝试按摩数据之外,您还可以做的另一件事是,如果您发现验证错误经常是由字段的顺序引起的(这是 xs 之间的 XSD 中的常见误解):sequence 和 xs:all),就是改变你的 XSD.将其从顺序切换到全部.你可以先试试官方的XSD.如果它通过了,那么您就不必验证松散的版本.

Besides trying to massage the data before validating it against the XSD, the other thing you can do, if you find that the validation errors are constantly being caused by simply the ordering of fields (which is a common misunderstand in XSD between xs:sequence and xs:all), is change your XSD. Switch it from sequence to all. You could try the official XSD first. If it passed, then you wouldn't have to validate for looser versions.

希望能帮到你...

这篇关于GPX Schema 验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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