Validating YAML with an XML DTD

蹲街弑〆低调 提交于 2020-01-13 18:10:54

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7430508/validating-yaml-with-an-xml-dtd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!