XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] Can every Salami Slice schema can be converted to anequivalent Russian Doll schema?

It's an open question whether a schema is expected to detect that two types with equivalent definitions are "the same type": the spec explicitly leaves this implementation-defined. So some schema processors might accept this.

But as for your general question, there are clearly schemas that cannot be represented in Russion Doll form, namely those whose structures are recursive: for example where element A of type T contains multiple elements A of type T.

Michael Kay
Saxonica



On 21 Feb 2022, at 17:26, Roger L Costello <costello@mitre.org> wrote:

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




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS