Using xs:extension for xs:restriction giving error

This should cover W3C XML Schema, Relax NG and DTD related problems.
sarvesh1
Posts: 1

Using xs:extension for xs:restriction giving error

Fri Apr 11, 2014 6:27 pm

Hi,

Not able to compile <xs:complexType name="ChargeableDataList"> in below code, urgent help required

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:simpleType name="StringMin1">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
   
    <xs:complexType name="CustomData">
        <xs:annotation>
            <xs:documentation>Additional implementation specific data that is required for rating</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Name" type="StringMin1"/>
            <xs:element name="Value" type="xs:string">
                <xs:annotation>
                    <xs:documentation>When the type is date, the format must be dd-mm-yyyy. Example: 25-11-2007</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Type">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="STRING"/>
                        <xs:enumeration value="INTEGER"/>
                        <xs:enumeration value="DOUBLE"/>
                        <xs:enumeration value="DATE"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CustomDataList">
        <xs:annotation>
            <xs:documentation>Additional implementation specific data that is required for rating</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="Data" type="CustomData" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:attribute name="Name" type="StringMin1" use="optional"/>
    </xs:complexType>

    <xs:complexType name="ChargeableDataType">
        <xs:complexContent>
            <xs:extension base="CustomData">
                <xs:sequence>
                    <xs:element name="Location" type="xs:string" minOccurs="0"/>
                    <xs:element name="Surcharges" minOccurs="0">
                        <xs:annotation>
                            <xs:documentation>If  surcharges are applicable to this type, those surcharges are attached in the response</xs:documentation>
                        </xs:annotation>
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="SurchargeInfo" type="xs:string" maxOccurs="unbounded"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                    <xs:element name="Adjustments" minOccurs="0">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="SurchargeAdjustment" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ChargeableDataList">
        <xs:complexContent>
            <xs:restriction base="CustomDataList">
                <xs:sequence>
                    <xs:element name="Data" type="ChargeableDataType" maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="Name" type="ChargeableEntity" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="ChargeableInfoType">
        <xs:annotation>
            <xs:documentation>Specify sets of values for catagories like documents, day factors, etc. so that charges can be attached</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="ChargeableInfo" type="ChargeableDataList" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:simpleType name="ChargeableEntity">
        <xs:union>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="Document"/>
                    <xs:enumeration value="DayFactor"/>
                </xs:restriction>
            </xs:simpleType>
            <xs:simpleType>
                <xs:restriction base="StringMin1"/>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>
</xs:schema>
   

Getting following Error:
[Xerces] derivation-ok-restriction.2.1.2: Error for type 'ChargeableDataList'. The attribute use 'Name' in this type has type 'ChargeableEntity', which is not validly derived from 'StringMin1', the type of the matching attribute use in the base type.
radu_pisoi
Posts: 334
Location: Craiova

Re: Using xs:extension for xs:restriction giving error

Mon Apr 14, 2014 12:57 pm

Analyzing your sample code, I suppose you are trying to restrict a complex type to change the type of a local attribute or element.

In this case you should refer a type that is a valid restriction of the original one. In your case you are trying to change the type of the 'Name' attribute from 'StringMin1' to 'ChargeableEntity'. This is an error because the type 'ChargeableEntity' is not a valid restriction of the type 'StringMin1'.

The same problem is related to the type of the 'Data' element. If you want to change it, then you should refer a type that is a valid restriction of the original one.

You can can find more details about complex type derivation rules in one of the XML Schema related books, recommended by us on our website: http://oxygenxml.com/xml_books.html.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests