Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Schema (XSD) - if one element has specific value then another element must be present and vice versa

Tags:

xsd

Can I express this in an XSD?

For example: One element is a required bool element named EmployedMoreThanThirteenWeeks and if the value is set to false I want the schema to require the existence of another element named EmploymentDate. And the other way around if the value is true then ideally the EmploymentDate element should be denied but I can accept it being optional.

like image 459
lox Avatar asked Sep 10 '09 12:09

lox


1 Answers

No. An XSD just defines structure and data types, not relations. It is possible to add a key reference between elements but that won't prevent invalid nodes, just invalid values.

You can create an XSLT file (an XML Stylesheet) which will validate the XML file for you and thus generate a report of errors.

like image 94
Wim ten Brink Avatar answered Sep 21 '22 00:09

Wim ten Brink