xmlxsdxmlspy

XML XSD problem with xs:restriction for different enumeration


I generated XSD file from my xml. xml...

`                   <Edits>
                    <Item id="AlignmentLargerThanSize">0.0</Item>
                    <Item id="Machine">PI-8200</Item>
                    <Item id="PackagePCBNames">Deepest level</Item>
                    <Item id="ManualExactOutlineStroke">10.0</Item>
                    <Item id="AlignmentPoint1Y">0.0</Item>
                    <Item id="PolarityComboBox">Positive</Item>
                    <Item id="AlignmentLessThanSize">10.0</Item>`

generated xsd made...

`   <xs:element name="Item">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="ST_Item">
                    <xs:attribute name="id" use="required">
                        <xs:simpleType>
<xs:restriction base="xs:string">                               <xs:enumeration value="AlignmentLargerThanSize"/>
<xs:enumeration value="Machine"/>
<xs:enumeration value="PackagePCBNames"/>
<xs:enumeration value="ManualExactOutlineStroke"/>
<xs:enumeration value="AlignmentPoint1Y"/>
<xs:enumeration value="PolarityComboBox"/>
<xs:enumeration value="AlignmentLessThanSize"/>

` then the restriction was made like...

`   <xs:simpleType name="ST_Item">
        <xs:restriction base="xs:string">
            <xs:enumeration value=""/>
            <xs:enumeration value="0"/>

` !!!! But I need specific restiction for each enumeration!!!!

Something like..

    `<xs:simpleType name="Item1" id="AlignmentLessThanSize">
        <xs:restriction base="xs:decimal">
            <xs:minInclusive value="0"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="Item2" id="AlignmentLargerThanSize">
        <xs:restriction base="xs:decimal">
               <xs:minExclusive value="0"/>
        </xs:restriction>
    </xs:simpleType>`

Solution

  • When an XML document contains several sibling elements with the same name, it's an XSD rule that those elements must all have the same type. You can't declare one type for the first element, another type for the second, and so on. The rule is called "Element Declarations Consistent", if you want to look it up.