0

I have following XML:

<entity>
    <category>Foo</category>
    <subcategory>Foo1</subcategory>
</entity>

Now i want to have only specific subcategories allowed. I would start with following XSD:

    <xs:element name="entity">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="category" type="categories"/>
                <xs:element name="subcategory" type="???"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

    <xs:simpleType name="categories">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Foo"/>
            <xs:enumeration value="Bar"/>
            <xs:enumeration value="many other categories"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="fooSubCategories">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Foo1"/>
            <xs:enumeration value="Foo2"/>
            <xs:enumeration value="FooN"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name="barSubCategories">
        <xs:restriction base="xs:string">
            <xs:enumeration value="Bar1"/>
            <xs:enumeration value="Bar2"/>
            <xs:enumeration value="BarN"/>
        </xs:restriction>
    </xs:simpleType>

now i read about the assert-element in XSD 1.1: XML Restrict based on another element value. XSD 1.1 has also rules as i read.

How would I do that? I tried to expand my subcategory element and insert a xs:choice element but that's not allowed in the specification.

itsfoobar
  • 29
  • 6

1 Answers1

0

After thinking about it a while i'll use one category field:

<xs:enumeration value="Foo"/>
<xs:enumeration value="Foo/Bar1"/>
<xs:enumeration value="Foo/Bar2"/>
<xs:enumeration value="Foo/Bar3"/>
<xs:enumeration value="Foo/Bar3"/>
<xs:enumeration value="Foo/Bar4"/>
<xs:enumeration value="Foo/Bar4/Baz1"/>

Semantically not the best but this has no limitations in depth.

Nevertheless: If you have time, a solution and wants to help someone in future feel free to post your Solution.

itsfoobar
  • 29
  • 6