18th
2009
Oct
permalink

Alternative to XML Validation

The desire to validate the structure of a document has come up a number of times recently. Say you have a public service where one of its operations takes in a complicated tree-structured document. You want a way to:

  1. use a programming-language-agnostic data format for your document;
  2. formally specify the expected structure of the doc;
  3. validate that input to calls to your service actually follow the structure;
  4. and hopefully, allow clients to do this validation themselves, w/o hitting your service.

A well-known language-agnostic way of doing all this is with XML as your document format, an XML schema as your specification of the expected structure, and XML validation as the publicly known algorithm for validating.

Having done some type-theory, I would much rather say that my data format is a data structure in a programming language, the spec of the structure is a type declaration, and validation is type-checking.

So I’ve wondered, is there a solution to my problem 1 through 4 — without using XML?

A few well-known programming-language-agnostic data-formats are: s-expressions, JSON, YAML. I have found Kwalify for YAML, but not much else.

This is a shame because people who believe they might ever need 2 through 4, choose XML for 1 (pl-agnostic data format) simply because they don’t know of any alternatives. This sucks because if all you are doing is 1, then you’ve made the worst choice for the job.

XML sucks to read as a human b/c there is so much extra noise. It gets to the point where the majority of your effort spent reading XML is filtering. It also sucks to use in programming b/c the API is terrible. XML doesn’t map perfectly to the data-structures in most languages, even Java, its biggest fan.

So again, if all you’re using it for is 1 — a programming-language-agnostic data format — XML is one of the worst choices. Yet, the fact that XML dominates in 2 through 4, it remains the default.

2 notes

  1. plpatterns posted this
blog comments powered by Disqus