使用XML DTD验证YAML [英] Validating YAML with an XML DTD

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

问题描述

我在系统上使用大量遗留代码,要求来自其他部门的各种人员,他们几乎没有技术经验,或者根本没有技术经验,他们必须学习XML(以及相当复杂的DTD集合)才能将文件数字化,然后传递给一些专门设计用于使用XML的专用设备.

I work with a tremendous volume of legacy code on system that requires people of all sorts from other departments with little or no technical experience to have to learn XML (and a rather elaborate set of DTDs) for the digitizing of documents, which then get passed on to some specialized devices designed specifically to use the XML.

在我看来,对于真正不了解标记语言的人来说,YAML或JSON(或其他我从未听说过的东西?)在人类创作方面可能要容易得多.是否有一个库(对于Visual Studio来说是理想的,所以我可以避免使用诸如Ruby之类的简单东西的公司繁文tape节)可以针对大量XML DTD验证YAML,或者首先需要以某种方式将YAML完全转换为XML和/然后/已验证?

It occurred to me that YAML or JSON (or something else I haven't heard of at all?) might be far easier on the human authoring end for people who really don't know the first thing about markup languages. Is there a library out there (ideally for Visual Studio so I can avoid the corporate red tape involved in using something easier like Ruby) that can validate YAML against a massive XML DTD or does the YAML first need to be converted somehow in full to XML and /then/ validated?

我担心的是,允许他们在YAML中进行编写以免于使用XML的麻烦的工具的内部用户不会知道如何处理验证错误,由于该错误已经被进一步消除了经历了一次转化.

My fear is that the in-house users of a tool that would let them author in YAML to save them the trouble of working with XML wouldn't know what to do with a validation error that is further removed due to having already been through a conversion.

推荐答案

我不知道这种工具是否存在,但是即使存在,也可能无法足够精确地产生有意义的错误消息给用户.即使编写XML,DTD或XSD也会经常产生非常难以理解的错误消息.

I don't know if such a tool exists, but even if it did, it would probably be impossible for it to be precise enough to yield meaningful error messages to the user. Even when authoring XML, a DTD or XSD will often yield very hard to understand error messages.

但是,编写这样的工具并不难.这就是将YAML转换为可以由XSD中的规则验证的内容.可以通过将YAML转换为XML,然后验证该XML来实现,但是也可以通过将XSD或DTD编译为C#,然后构建C#代码期望的对象树来实现.

However, writing such a tool won't be too hard. It's all about translating the YAML into something that can be validated by the rules in the XSD. That can be achieved by translating YAML to XML and then validating that XML, but it can also be done by compiling an XSD or DTD to C# and then building the object tree expected by the C# code.

也许,如果这样的工具保留了有关YAML的元数据(如行号和字符号),则可能会向用户返回一些有意义的错误消息.如果首先将XSD或DTD转换为C#,则可能尤其如此,因为在C#中,您对XML本身的依赖性较小,并且可以更轻松地将验证扩展为适合YAML的内容.

Perhaps if such a tool preserved metadata about the YAML (like line and character numbers), somewhat meaningful error messages could be returned to the user. That might especially be true if the XSD or DTD is first translated to C#, since in C# you're less dependent on the XML itself and can more easily expand the validation to something that fits with the YAML.

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

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