답변됨 xsd files, base and derivation

  • 2012년 2월 21일 화요일 오전 9:43
     
     

    Hi,

    I have declared a type in x.xsd file.

    But I wanted override teh type in y.xsd file. But its not allowind. Its telling, Invalid Particle derivation by restriction.

    Please let me know if you have across this kind of issue?

모든 응답

  • 2012년 2월 21일 화요일 오전 10:23
     
     

    Well you will need to show us the exact sample code, otherwise we don't know what you tried and can't explain why it fails.

    The schema primer has two sections on deriving types, http://www.w3.org/TR/xmlschema-0/#DerivExt and http://www.w3.org/TR/xmlschema-0/#DerivByRestrict.


    MVP Data Platform Development My blog

  • 2012년 2월 21일 화요일 오전 10:56
     
     

    The below type is defined in my base.xsd

    <xsd:complexType name="ABC">
        <xsd:sequence>
          <xsd:element name="A" type="xsd:string" minOccurs="1" maxOccurs="1">
           </xsd:element>
          <xsd:element name="B" type="xsd:string" minOccurs="1" maxOccurs="1">
          </xsd:element>
          <xsd:element name="C" type="base:C" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
      </xsd:complexType>

    Now I need to override the above type in my derived.xsd

     <xsd:complexType name="ABC1">
        <xsd:complexContent>
          <xsd:restriction base="base:ABC">
            <xsd:sequence>
              <xsd:element name="A" type="xsd:string" minOccurs="0" maxOccurs="1" >
              </xsd:element>
              <xsd:element name="B" type="xsd:string" minOccurs="1" maxOccurs="1">
              </xsd:element>
              <xsd:element name="C" type="derived:C" minOccurs="0" maxOccurs="unbounded"/>
            </xsd:sequence>
          </xsd:restriction>
        </xsd:complexContent>
      </xsd:complexType>

    But when I write this in my derived xsd, it is giving me the below for <xsd:complexType name="ABC1"> line.

    Invalid particle derivation by restriction. "Derived element <namespace>:A is not a valid restriction of base element <namespace>:A according to Elt:Elt - Nameandtype OK."

    Please help how to acheive this ?

  • 2012년 2월 21일 화요일 오후 1:13
     
     답변됨

    I can't comment on the highlighted part with type="base:C" and type="derived:C" has you have omitted the definitions of these types but as the error message relates to element "A" I think your attempt to have

      xsd:element name="A" type="xsd:string" minOccurs="1" maxOccurs="1"

    in the base type and then to try to change that to

      xsd:element name="A" type="xsd:string" minOccurs="0" maxOccurs="1"

    in the derived type is not something the W3C schema language in version 1.0 allows as any instance to is of the derived type must also be an instance of the base type. But if the base type requires element "A" while the derived type does not an instance of the derived type would not be an instance of the base type. For details see http://www.w3.org/TR/xmlschema-0/#DerivByRestrict which says "In fact, the values represented by the new type are a subset of the values represented by the base type (as is the case with restriction of simple types). In other words, an application prepared for the values of the base type would not be surprised by the values of the restricted type. ".


    MVP Data Platform Development My blog

    • 답변으로 표시됨 Venkatesh Basi 2012년 10월 3일 수요일 오전 12:00
    •