Validating YAML with an XML DTD
Asked Answered
W

1

4

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.

Which answered 15/9, 2011 at 12:6 Comment(0)
C
3

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.

Chavers answered 15/9, 2011 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.