Search code examples
xmlxsdxsd-validationxsd-1.0

Value based conditional restriction in XSD 1.0


Below is my sample XML:

  <RootElement attributeName="Value1">
    <ChildElement>0</ChildElement>
    <ChildElement>1</ChildElement>
    <ChildElement>2</ChildElement>
    <ChildElement>3</ChildElement>
  </RootElement>

I want to add restriction based on value of attributeName. Value of attributeName can be Value1|Value2|Value3. If the value of attribute name is Value1 or Value2 then no child element should be present. If the value of attribute name is Value3 then there should be min 1 and max 15 ChildElement occurrences. I want to achieve this with XSD v1.0. I found some solutions with XSD v1.1 but I can't use them because I want to achieve this in XSD v1.0. I found some solutions with abstract and choice but with that it provide different child elements names. I can have only "ChildElement". I can't use other child elements.


Solution

  • This kind of restriction is not possible with XSD 1.0. You can achieve same by using Assert or Rule in XSD 1.1 or later.