I have this XML, and the name
attribute values should be unique like A
, B
, etc:
<preDefinedRecipes>
<preDefinedRecipe type="BREAD" name="A" ordinal="1" writerLevel="Service">
<description> <!-- // optional-->
</description>
<parameterDef ref="SUGAR_QTY" value="3" />
<parameterDef ref="SALT_QTY" value="3" />
<parameterDef ref="OIL_QTY" value="1" />
</preDefinedRecipe>
<preDefinedRecipe type="BREAD" name="B" ordinal="2" writerLevel="Service">
<description> <!-- // optional-->
</description>
<parameterDef ref="SUGAR_QTY" value="5" />
<parameterDef ref="SALT_QTY" value="7" />
<parameterDef ref="FLOUR_QTY" value="3" />
</preDefinedRecipe>
</preDefinedRecipes>
This is my XSD file:
<xs:complexType name="preDefinedRecipeType">
<xs:sequence>
<xs:element type="xs:string" name="description">
</xs:element>
<xs:element type="preDefinedRecipeParameterDefType" name="parameterDef" maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
<xs:attribute type="xs:string" name="type" use="required"/>
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:byte" name="fieldbusId" use="optional"/>
<xs:attribute type="xs:byte" name="ordinal" use="required"/>
<xs:attribute type="xs:string" name="writerLevel" use="required"/>
<xs:unique name="uniqueTitle">
<xs:selector xpath="recipeConfig/preDefinedRecipes/preDefinedRecipe"/>
<xs:field xpath="@name"/>
</xs:unique>
</xs:complexType>
<xs:complexType name="preDefinedRecipesType">
<xs:sequence>
<xs:element type="preDefinedRecipeType" name="preDefinedRecipe" maxOccurs="unbounded" minOccurs="0">
<xs:annotation>
<xs:documentation>Default recipe names shall be translatable, user defined recipes shall never be
translated to avoid collisions.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>
I added xs:unique
element for the field and selector, but it gives the following error:
SAX Exception: s4s-elt-invalid-content.1: The content of
preDefinedRecipeType
is invalid. Elementunique
is invalid, misplaced, or occurs too often.
I think I am doing something wrong, but I am new to XSD and do not see it.