XML : How do use inheritance in xsd to make multiple elements type of another

I want to model Xml such as

  .......  <mood1>     <positive>true</positive>     <probability>23</probability>  </mood1>  <mood2>     <positive>false</positive>     <probability>86</probability>  </mood2>  .........    

in an xml schema, currently I have

  <xs:element name="mood1">    <xs:complexType>        <xs:sequence>            <xs:element ref="category"/>        </xs:sequence>  </xs:complexType>  <xs:element name="mood2">    <xs:complexType>        <xs:sequence>            <xs:element ref="category"/>        </xs:sequence>  </xs:complexType>  <xs:element name="category">  <xs:complexType>    <xs:sequence>      <xs:element name="positive" type="xs:boolean"/>      <xs:element name="probability" type="xs:float"/>    </xs:sequence>  </xs:complexType>    

but of course that would model having an additional unneccessary category element such as

  .......  <mood1>     <category>        <positive>true</positive>       <probability>23</probability>     </category>   </mood1>  <mood2>    <category>      <positive>false</positive>      <probability>86</probability>    </category>  </mood2>  .........    

which I dont want.

I could do

  <xs:element name="mood1">    <xs:complexType>        <xs:sequence>          <xs:element name="positive" type="xs:boolean"/>          <xs:element name="probability" type="xs:float"/>        </xs:sequence>  </xs:complexType>  <xs:element name="mood2">    <xs:complexType>        <xs:sequence>          <xs:element name="positive" type="xs:boolean"/>          <xs:element name="probability" type="xs:float"/>        </xs:sequence>  </xs:complexType>    

But then I have to keep on repeating the same definition (and there is more than just mood1 and mood2).

I want to say mood1 is a subtype of category but I don't know how to, its worth noting mood1 and mood2 do have identical elements but they are not the same thing.

No comments:

Post a Comment