I have an element that can have a different structure depending on certain constraints. The element is defined as:
<xs:complexType name="MyElement">
<xs:sequence>
<xs:element name="Child"/>
<xs:element name="Child1" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
I also have an element that has several MyElement
. But I want to be able to say that
- The first occurrence must have a Child1 and for all other occurrences Child1 can be optional.
- All odd occurrences must have a Child1 and for even occurrences Child1 can be optional.
- If the value of Child is equals to R then the element Child1 must be present.
I don’t want a solution; I want to know what technology you would use to solve this kind of problem. Schema only or Sche开发者_开发百科ma and Schematron? I am interested in knowing the scope of XML Schema and Schematron.
You would need to use Schematron with Schema 1.0.
Schema does not have the facility to express the conditional logic that you describe. Schematron is perfect for this scenario and could easily be used to encode and validate these validation rules.
It may be possible to define such restrictions/validations using Schema 1.1 assertions.
精彩评论