Search code examples
xmlxsdversioning

Validate XML by its correct XSD version


we are dealing with several XSD's and XML files for different versions. We want to make sure that a xml file can be validated with its correct XSD. Is there a way to do it? So far I've come to this conclusions:

  • You can versioning the xsd by setting the "version" attribute within the root element of the schema (easy :) )
  • To do the same for the xml you can either put it in the comment section or in an attribute in the root element (both would require preprocessing when importing and after processing after export to write the version) - very nasty ;-)

I should also mention that we can't make sure the xml we get is correct to any XSD, because it can be passed by a third party.

Any help is appreciated!


Solution

  • I would put a version number on the root element, and then use an XProc pipeline to control the validation, where the XProc pipeline decides which schema to validate against based on what it sees in the version number.