0

In xsd i have elements like below, where it requires city,zip to be not empty.

<addresses>
    <address>
      <name>abc</name>
      <address>skip</Address>
       ....
      <city/>
      <zip/>
    </address>
</addresses>

but in specific cases e.g. if address element content is skip, i dont want city,zip to be validated. What is the option to achieve this java or at xsd level.

  • To achieve this, turn schema validation off, and perform all validation in Java code. --- Or just remove constraint of `` and `` so they are optional, and enforce them to be required in Java code when `
    ` is present.
    – Andreas Mar 18 '19 at 16:12

1 Answers1

1

You probably ought to frame your requirements not in terms of skipping validation but rather requiring occurrence or type based upon conditions. Generally "skipping validation" is handled by xs:any, but that doesn't really appear to be what you want here.

XSD 1.0 cannot express constraints where element occurrence is dependent upon the value of other elements. You'll need XSD 1.1 for that. For an example, see Require XML element in XSD when another element has certain value?

kjhughes
  • 106,133
  • 27
  • 181
  • 240