tags:

views:

13

answers:

1

Given the following xml example:

<MyCustomXml>
    <ClientId>SomeGuid</ClientId>
    <Contact>[email protected]</Contact>
    <Data>
        <Item name="SomeName" type="String">
            SomeValue
        </Item>
        <Item name="SubList" type="List">
            <Data>
                <Item name="AnotherItem" type="String">
                    Hello
                </Item>
                <Item name="Key2" type="String">
                    World
                </Item>
                <Item name="Sub2" type="List">
                    <Data>
                        <Item name="KeeyGoing" type="String">
                            The Sub list can keep going infinately
                        </Item>
                    </Data>
                </Item>
            </Data>
        </Item>
    </Data>
</MyCustomXml>

I created the following xsd for this xml

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <xs:element name="MyCustomXml" >
        <xs:complexType>
            <xs:all>
                <xs:element name="ClientId" type="xs:string" minOccurs="0" maxOccurs="1"/>
                <xs:element name="Contact" type="xs:string" minOccurs="0" maxOccurs="1" />
                <xs:element ref="Data" minOccurs="0" maxOccurs="1" />
                </xs:all>
        </xs:complexType>
    </xs:element>

    <xs:element name="Data" substitutionGroup="Data">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="Item" maxOccurs="unbounded" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Item" substitutionGroup="Item">
        <xs:complexType mixed="true">
            <xs:sequence>
                <xs:element ref="Data" minOccurs="0" />
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="required" />
            <xs:attribute name="type" use="required" />
        </xs:complexType>
    </xs:element>

</xs:schema>

Accoding to http://www.validome.org/grammar/validate/ the xsd is not valid. The following errors are:

Line 13 Column: 55
Error: Circular substitution group detected for element ':Data'.
Error Position:

Line 20 Column: 55
Error: Circular substitution group detected for element ':Item'.
Error Position:

How do I resolve the circular substitution? I tried changing the substitutionGroup but that did not work.

+1  A: 

You do not need the substitutionGroup. At least not for the above XML example. The substitutionGroup is only needed if you want to allow a substitution of an element "in place".

In your schema you would allow a substitution of <Data> with <Item> which can be substituted with <Data> which can be substituted with <Item> ...

Apart from this your schema looks suitable for that what you want to achieve.

Enton
Awesome works perfectly.
David Basarab