I have the following xml which has xsd schema, but is poor and no use for serialization.
<rulestruct>
<rule>
<type name="vector" />
<ruleident ruleidentifier="" />
<pattern type="" />
</rule>
<rule>
<type name="expression" />
<ruleident ruleidentifier="" />
<pattern type="" />
</rule>
<rule>
<type name="vector" />
<ruleident ruleidentifier="" />
<pattern type="" />
</rule>
<rule>
<type name="statement" />
<ruleident ruleidentifier="" />
<pattern type="" />
</rule>
<rule>
<type name="statement" />
<ruleident ruleidentifier="" />
<pattern type="" />
</rule>
</rulestruct>
Each rulestruct can have 1.N rules. Each rule can be repeated. Order must be preseved. Each rule has 1.N elements, some have 9 elements, others have 10, 13. There are 9 different rule types.
I was thinking of using a elements group to represent each rule type but i’m not quite sure how to map it.
If you want to preserve the same name of element (rule) for various rule types, you defined abstract element (attribute
abstract="true") and all of its children will havexs:ComplextContent>xs:extensionwith base attribute equal to your abstract type name.In your XML each rule element must have
xsi:typeattrite to distinguish element concrete type.Explanation and example are here.
If you want/can use different element names for each rule type, you can use substitution groups. You common ancestor is again defined by attribute abstract. The concrete types are defined as xs:element with attribute
substitutionGroupequal to name of common ancestor.Explanation and example are here.