使用 XML DTD 验证 YAML

发布于 2024-12-04 17:45:02 字数 400 浏览 5 评论 0原文

我在系统上处理大量遗留代码,需要来自其他部门的各种技术经验很少或没有技术经验的人员必须学习 XML(以及一组相当复杂的 DTD)来对文档进行数字化,然后通过一些专门设计用于使用 XML 的专用设备。

我突然想到,对于那些真正不了解标记语言的人来说,YAML 或 JSON(或者我根本没有听说过的其他东西?)在人类创作端可能要容易得多。是否有一个库(对于 Visual Studio 来说是理想的选择,这样我就可以避免使用像 Ruby 这样更简单的东西所涉及的公司繁文缛节)可以根据大量 XML DTD 验证 YAML,或者 YAML 首先需要以某种方式完全转换为 XML然后/然后/验证?

我担心的是,工具的内部用户可以使用 YAML 进行编写,从而省去使用 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.

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?

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.

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

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

发布评论

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

评论(1

无人接听 2024-12-11 17:45:02

我不知道这样的工具是否存在,但即使存在,它也可能不可能足够精确以向用户产生有意义的错误消息。即使在编写 XML 时,DTD 或 XSD 通常也会产生非常难以理解的错误消息。

然而,编写这样一个工具并不会太难。这一切都是为了将​​ YAML 转换为可以通过 XSD 中的规则进行验证的内容。这可以通过将 YAML 转换为 XML,然后验证该 XML 来实现,但也可以通过将 XSD 或 DTD 编译为 C#,然后构建 C# 代码所需的对象树来实现。

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

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.

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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文