Using XML schemas to describe data that you need to exchange with 3rd parties is great. Schemas define a machine-readable format that can be directly re-used by developers on the “other side”. Now isn’t that a win-win situation if you ever saw one?
However, while I think that schemas should be regarded as contracts, if you are designing schemas that will be handed over to business partners, you should think about them long and hard. Once you hand them over, there’s no turning back: these schemas now live in a world over which you have no control. You do not know how and where they will be used, nor can you estimate what impact a possible change may have on your business partners.
Handing out a schema is like signing a contract: it becomes carved in stone. Schemas you have shared with business partners should be regarded as immutable. There’s really no such thing as a schema change. There’s only new schemas…
That’s why I’m all for building schemas with flexibility in mind. They should only be as strict as they really, really, really need to be (and even then subtract another 20%
). If you’re the schema creator, you have to keep that in mind all the time, and you must think about the possible scenarios that may result from what you are doing.
Don’t think about schemas as a developer, think about them as a business user.
Here’s an example: do you really want to refuse a 100.000€ order message with an “invalid messsage” error the moment you receive it – annoying the crap out of your customer, your salespeople, and probably your CEO in the process – because the customer’s software may not be as strict as yours and he accidently misformatted the order date? Keep in mind that there (usually) are humans in your organisation, who can look at that misformatted date and either interpret it, or pick up the phone and call the customer. The goal is not avoiding errors, the goal is allowing the order to be processed even in case of correctable errors.
In other words, you should be able to deal with a lot of eventualities in the business processes that sit behind your interfaces. That’s the place where you really define your level of flexibility. Your XML schemas should allow for that flexibility.
A good way to think about that is to regard messsages you receive from customers not as something that needs to be stuffed in databases and therefore needs to be tightly controlled.
The XML order message you receive from your customer isn’t the order itself!
Instead, it’s just the trigger that starts your internal order process, during which you can validate, correct, enrich, and route the data to wherever it needs to be. The result of that process is an order (and probably some other things as well).
Your customers, salespeople and CEO will be grateful…