News for hackers. Stuff that matters.
Re:XML Can Give the Same Performance as JSON by lmm on Thursday August 15, 2013 @10:08AM (#6217817)
The thing is it's almost impossible to express all the constraints on your input in schema. You certainly can't encode "userId must match a user that exists in the database" as part of a schema. So with XML you end up having two validation processes - the schema and then the part of your code that checks that the input datum really is valid. And then when the time comes to add another check you realize that code is a much more expressive way to write your constraints, and it's always possible for input to be rejected at the code stage, so you might as well just add your check there. So the schema level ends up being a useless extra complication.
Re:XML Can Give the Same Performance as JSON by zdw on Thursday August 15, 2013 @12:15PM (#6218790)
I don't think you get what schemas are for. Schemas don't validate the content - they validate the structure and variable types. It doesn't magically make the data valid. It lets you make assumptions about how that data is structured.

The advantage of a schema is that one schema can be used in multiple languages. Someone's Lua based embedded system can run the same schema as a Go program on a 32 CPU box.

You can give someone a well written schema, tell them "make your data like this, and run the validator when you open and save your XML". In this way, it's a free, one line (in most languages) structure sanity check.

Re:XML Can Give the Same Performance as JSON by lmm on Thursday August 15, 2013 @12:46PM (#6219060)
>I don't think you get what schemas are for. Schemas don't validate the content - they validate the structure and variable types. It doesn't magically make the data valid. It lets you make assumptions about how that data is structured.

In a typed language the very first stage of deserialization, the "turn this from a string into objects in my language" step, will do that for you "for free".

In an untyped language I guess it could be helpful, but again: it's almost always easier to write these sort of checks in a general purpose programming language than in XML schema.

>The advantage of a schema is that one schema can be used in multiple languages. Someone's Lua based embedded system can run the same schema as a Go program on a 32 CPU box.

If that's what you want there are more robust and performant approaches, e.g. thrift.

>You can give someone a well written schema, tell them "make your data like this, and run the validator when you open and save your XML". In this way, it's a free, one line (in most languages) structure sanity check.

Right, but that doesn't tell them what they think it means. It doesn't make the request valid.