What is a XML schema in plain simple terms? What will be the problem if an XML doesn't have a schema defined? An example can be very helpful.
The main problem I see is that it cannot be validated either against a DTD, or against an XML Schema. As such, you don't have any guarantee that what you received is what you expected.
For example, if you are sending this XML file to someone:
<x id="2"> <yyy> <zzz>fdslgskfmlsdk</zzz> <zzz>sdmflsdmfl</zzz> </yyy> <yyy>thingy</yyy> </x>
How can he be certain that:
- is "id" always a number ?
- is "id" mandatory or optional ?
- is "id" the only attribute of the "x" element ?
- how many "yyy" elements can be contained in a "x" element ?
- is "yyy" the only element that can be inside "x" ?
- how many "zzz" elements in a "yyy" element ?
There is an unlimited list of questions that person can ask to you. The goal of an XML Schema is to hopefully answer all these questions and also to provide a way to validate a document before or during the parsing phase.
Not fond of w3schools, but here is a list of short and interesting reads on XML Schema:
It's the same question as using a static or dynamically-typed language. Schema is a declarative check on the correctness of your data. If you have a field that has to be an integer, you can mark as such in your schema and then invalid data won't get past the validator. Without a schema, you would have to check in your code which is more error-prone. Sometimes, you might have a preference for flexibility in which case a schema is a hindrance. Notably there is no standard schema language for JSON, yet it is growing in popularity.