I like to create an element that has different subelements depending on the value of one of these elements. I wonder if and how I can achieve this (best possible solution). So if the Type is piece there must be a Weight element. If the Type is kilogram or gram or ... it does not need it.
<?xml version="1.0" encoding="UTF-8"?>
<Amounts>
<Amount>
<Type>piece</Type>
<Value>6</Value>
<Weight>
<Value>1.5</Value>
<Type>liter</Type>
</Weight>
</Amount>
<Amount>
<Type>kilogram</Type>
<Value>0.610</Value>
</Amount>
</Amounts>
So I thought I might do something like this, but I get errors (see below).
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://ift.tt/tphNwY" targetNamespace="http://ift.tt/1vQ9BYc"
xmlns:amount="http://ift.tt/1vQ9BYc" elementFormDefault='qualified'>
<element name="Amount">
<complexType>
<choice>
<group ref="amount:kilogram" />
<group ref="amount:piece" />
</choice>
</complexType>
</element>
<group name="kilogram">
<sequence>
<element name="Type" fixed="kilogram" />
<element name="Value" type="float" />
</sequence>
</group>
<group name="piece">
<sequence>
<element name="Type" fixed="piece" />
<element name="Value" type="int" />
<element name="Weight">
<complexType>
<sequence>
<element name="Type" type="amount:amountType" />
<element name="Value" type="float" />
</sequence>
</complexType>
</element>
</sequence>
</group>
<simpleType name="amountType">
<restriction base="string">
<enumeration value="kg" />
<enumeration value="g" />
<enumeration value="mg" />
<enumeration value="lb" />
</restriction>
</simpleType>
</schema>
Error I get at line 5 is:
Multiple annotations found at this line: - cos-nonambig: "http://ift.tt/1vQ9BYc":Type and "http://ift.tt/1vQ9BYc":Type (or elements from their substitution group) violate "Unique Particle Attribution". During validation
against this schema, ambiguity would be created for those two particles. - cos-element-consistent: Error for type '#AnonType_Amount'. Multiple elements with name 'Value', with different types, appear in the model group.
 
No comments:
Post a Comment