Hi Folks,
Here is a schema that uses the Salami Slice design:
<xs:schema
xmlns:xs=http://www.w3.org/2001/XMLSchema>
<xs:element name="Test" type="TestType" />
<xs:complexType name="TestType">
<xs:sequence>
<xs:element ref="A" />
<xs:element ref="B" />
<xs:element ref="C" />
</xs:sequence>
</xs:complexType>
<xs:element name="A">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="B">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="B"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="C">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="C"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
Here is an equivalent Russian Doll schema. By “equivalent” I mean the schema produces the same validation results.
<xs:schema
xmlns:xs=http://www.w3.org/2001/XMLSchema>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="A">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="B">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="B"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="C">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="C"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The example seems to suggest that any Salami Slice schema can be converted to an equivalent Russian Doll schema. But is that always the case? Scroll down to see the answer ….
Question: Can every Salami Slice schema can be converted to an equivalent Russian Doll schema?
Answer: No!
If an element contains two child elements with the same name and same type, then the Salami Slice design can implement the element, but the Russian Doll design cannot. In the above example, suppose that the content of Test is not A, B,
C, but rather A, B, A:
<xs:schema
xmlns:xs=http://www.w3.org/2001/XMLSchema>
<xs:element name="Test" type="TestType" />
<xs:complexType name="TestType">
<xs:sequence>
<xs:element ref="A" />
<xs:element ref="B" />
<xs:element ref="A" />
</xs:sequence>
</xs:complexType>
<xs:element name="A">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="B">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="B"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
That is a valid schema.
But in the Russian Doll version:
<xs:schema
xmlns:xs=http://www.w3.org/2001/XMLSchema>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="A">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="B">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="B"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="A">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
we get a schema-valid error: Multiple elements with name 'A', with different types, appear in the model group.
Here’s why: XML Schema does not allow an element to hold two child elements with the same name unless the child elements can be determined to have the same type. A human can visually look at the Russian Doll schema and see that the two
A elements have the same type:
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="A"/>
</xs:restriction>
</xs:simpleType>
But an XML Schema validator cannot determine that they have the same type.
So, it is not possible to convert every Salami Slice schema to an equivalent Russian Doll schema.
/Roger