0

I have a set of XSD files in my project. I tried to validate them using the code, suggested in this question:

Validating XSD itself

It turned out, that some of my XSD files are not valid.

This doesn't prevent me from validating some XML with this not-valid XSD files. So in which situations that can really matter?

Community
  • 1
  • 1
MiamiBeach
  • 3,261
  • 6
  • 28
  • 54
  • "*This doesn't prevent me from validating some XML with this not-valid XSD files.*" Name names. That should not happen with a properly designed (and configured) validating XML parser; it should report the problem with the XSD and XML validation should fail. – kjhughes Oct 13 '14 at 20:55

2 Answers2

2

In addition to John's answer, if you use XML Schemas to define an interoperable protocol, you may want not just validate the schema but also

  • do it with several tools - not just Xerces but also OxygenXML and
  • try to compile this schema with standard tools like JAXB/XJC or Microsoft's xsd.

In my practice I had cases where international standardisation organisations published schemas which were simply invalid. Because they were only validated in a certain tool (I won't name it here). And I saw a lot of schemas which are technically valid but cause huge problems with XJC which is often use for web services.

If you just write and XML Schema for your own purposes and use it privately, then, initially noone cares if it is valid or not.

But don't forget that you may have no control over the future of your developments. An internal dirty prototype today may be a sold product tomorrow.

lexicore
  • 42,748
  • 17
  • 132
  • 221
0

If your XSD is not valid, then you cannot be confident that a schema processor will interpret it as you intended. After all, when you feed it gibberish, how is it supposed to know what you mean?

If there's only a little gibberish then it may turn out that your chosen processor will successfully validate some or even all inputs as you wanted, but that's a matter of luck. Other schema processors might validate differently -- even different versions of the same processor might do.

If you are struggling with that, then you should ask yourself why your application bothers with validating XML against XSD in the first place. If you didn't validate, then what kinds of variation from the expected XML form could your application tolerate? Can you be certain that every future version will be the same in that regard?

John Bollinger
  • 160,171
  • 8
  • 81
  • 157