Whatever the format, regardless of their own specific downsides, one of the most important issue is for clients to decide if the read data is correct or not.
When using JSON and YAML, the different clients need to provide ad hoc validation. Issues arise when the provider changes the data format:
- How to make clients aware that the format changed?
- What information to communicate to the client about the format change?
- How to keep validation synchronized across clients?
XML has this issue solved since the beginning by providing a grammar. A grammar plays the same role for a XML document as constraints and types in a SQL database. The most important difference is that you can externalize the grammar.
Several XML grammar implementations are available: Document Type Definition, XML Schema, Relax NG, etc. The most widespread one is XML Schema. Since a XML Schema is also written in XML format, a web server can host it. Then you can reference it by a publicly-accessible URL.
This approach solves the above issues: when a client receives an XML document, the former looks at the XML Schema URL. It can then fetch it, and check that the data conforms to the schema.
Changing the data format is as simple as versioning the XML Schema file, and publishing it under a new URL.
from Hacker News https://ift.tt/3j9hffM
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.