Search code examples
javaxmlxsdxsd-1.0

Conditions in XSD for validating XML


Does XML need to be strictly validated against XSD? How to validate condition based XML in XSD?

I have a scenario where I need to validate a condition. After doing some research I found that XSD 1.0 won't do condition based verification.

Example: based on an attribute 'Y' or 'N', I have to display different elements.

Please provide any suggestions.


Solution

  • No, XML does not have to be validated against XSD.

    XSD 1.0 is not capable of enforcing arbitrary constraints on your data. If you have constraints that cannot be enforced using XSD 1.0, you have a number of choices: redesign the XML, move to XSD 1.1, validate it using a different technology (including the option of writing your own custom validator, say in XSLT), or not validating it at all.