xml - XSD - Re-use/inheritance of tags -


i have 2 tags resemble kind of boolean expression:

<complextype name="condition">     <choice minoccurs="0">         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>     </choice> </complextype>  <complextype name="condition-a">     <all>         <element name="value" type="string"/>     </all> </complextype>  <complextype name="condition-b">     <all>         <element name="value" type="string"/>     </all> </complextype> 

i combine these conditions and, or , not constructions. this:

<condition>     <and>         <condition-a><value>x</value></condition-a>         <condition-b><value>y</value></condition-b>         <not>             <condition-a><value>z</value></condition-a>         </not>     </and> </condition> 

note condition tag used @ top, not inside and, or , not.

i came following definitions:

<complextype name="condition">     <choice minoccurs="0">         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>         <element name="and" type="myns:condition-and"/>         <element name="or" type="myns:condition-or"/>         <element name="not" type="myns:condition-not"/>     </choice> </complextype>  <complextype name="condition-a">     <all>         <element name="value" type="string"/>     </all> </complextype>  <complextype name="condition-b">     <all>         <element name="value" type="string"/>     </all> </complextype>  <complextype name="condition-and">     <choice maxoccurs="unbounded">         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>         <element name="and" type="myns:condition-and"/>         <element name="or" type="myns:condition-or"/>         <element name="not" type="myns:condition-not"/>     </choice> </complextype>  <complextype name="condition-or">     <choice maxoccurs="unbounded">         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>         <element name="and" type="myns:condition-and"/>         <element name="or" type="myns:condition-or"/>         <element name="not" type="myns:condition-not"/>     </choice> </complextype>  <complextype name="condition-not">     <choice>         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>         <element name="and" type="myns:condition-and"/>         <element name="or" type="myns:condition-or"/>         <element name="not" type="myns:condition-not"/>     </choice> </complextype> 

although works, not optimal. repeating possible conditions in and, or , not tags. side effect, generated jaxb code mess.

is there more elegant approach this?

instead of repeating same choice multiple times xml schema allows create global xs:group (xs:choice, xs:sequence or xs:all) , reference in other parts of schema, global types , elements.

so can use this:

<group name="anycondition">     <choice>         <element name="a" type="myns:condition-a"/>         <element name="b" type="myns:condition-b"/>         <element name="and" type="myns:condition-and"/>         <element name="or" type="myns:condition-or"/>         <element name="not" type="myns:condition-not"/>     </choice> </group>  <complextype name="condition-and">     <group ref="myns:anycondition" maxoccurs="unbounded"/> </complextype>  <complextype name="condition-or">     <group ref="myns:anycondition" maxoccurs="unbounded"/> </complextype>  <complextype name="condition-not">     <group ref="myns:anycondition"/> </complextype> 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -