Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9295493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:37:03+00:00 2026-06-18T21:37:03+00:00

When adding restrictions to complexTypes in XML Schemas , is it necessary to rewrite

  • 0

When adding restrictions to complexTypes in XML Schemas , is it necessary to rewrite all the elements used in the definition of the complexType? If so , Why can’t it just reuse the existing element definitions and overwrite the new restricted ones?

For example , In the below ; When I just want to restrict the field country , Should I rewrite all the 3 fields again?

<xs:complexType name="customer">
  <xs:sequence>
    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="country" type="xs:string"/>
  </xs:sequence>
</xs:complexType>

<xs:complexType name="Norwegian_customer">
  <xs:complexContent>
    <xs:restriction base="customer">
      <xs:sequence>
        <xs:element name="firstname" type="xs:string"/>
        <xs:element name="lastname" type="xs:string"/>
        <xs:element name="country" type="xs:string" fixed="Norway"/>
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType> 

So , It is pretty clear from the answer below as to why we have to rewrite the whole type.

Follow Up Question

What’s the use of this restriction feature then?

One situation , I can think of ; is when you have to validate instance documents containing restricted types in place of base types in xml schema.

Say , If “B” is the base type and its restricted to “B*”. Any instance document containing “B*” at the place where an element of type “B” is expected by the Schema Document would work.We would not have to write separate rules for each restricted type.(The attribute “xsi:type” in the instance document will validate it with the correct type.)Right?

Any Other uses of this feature?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:37:04+00:00Added an answer on June 18, 2026 at 9:37 pm

    Your first question is "When adding restrictions to complexTypes in XML Schemas, is it necessary to rewrite all the elements used in the definition of the complexType?" No, only the ones you want to be part of the definition of the restricted type. But yes, all of the ones that should be part of the restriction. The content model in the restriction must stand on its own as a complete definition of the content model of the type. (It does not, on the other hand, have to specify all the attributes; they are inherited without change unless otherwise specified.)

    Your second question is "Why can’t it just reuse the existing element definitions and overwrite the new restricted ones?" It’s a reasonable question. The answer is slightly tricky: Consider two arbitrary content models E and F. Now, we want to interpret F as a restriction of E that mentions only the elements and model groups in E that we want to change, and omits any mention of the elements and model groups we want alone. Is this a soluble problem, in the general case? Is it guaranteed to have a unique solution? It may seem obvious to you that the answer is yes in both cases, but it did not seem obvious to the designers of XSD at the time, and it does not seem obvious to me today.

    For example, let E be

    (a+, b+, c*){2}, (a+, b*, c+){3}
    

    and let F be

    a{3,4}
    

    If we assume that everything in F is a restriction of something in E and everything else in E should be left alone, does F mean we want to restrict E to

    (a{3,4}, b+, c*){2}, (a+, b*, c+)
    

    or to

    (a+, b+, c*){2}, (a{3,4}, b*, c+)
    

    ?

    Addendum

    @nikel asks for an XSD example. The example above is already an XSD example, though, so I suppose "an example in XSD syntax" is meant. I take the proposal to be that syntax like the following should work. First we have the base type, E:

    <xs:complexType name="E">
      <xs:sequence>
        <xs:sequence minOccurs="2" maxOccurs="2">
          <xs:element ref="a" maxOccurs="unbounded"/>
          <xs:element ref="b" maxOccurs="unbounded"/>
          <xs:element ref="c" minOccurs="0" 
                              maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:sequence minOccurs="3" maxOccurs="3">
          <xs:element ref="a" maxOccurs="unbounded"/>
          <xs:element ref="b" minOccurs="0" 
                              maxOccurs="unbounded"/>
          <xs:element ref="c" maxOccurs="unbounded"/>
        </xs:sequence>
      </xs:sequence>
    </xs:complexType>
    

    Now let us imagine that we want type F to be able to restrict E without specifying a full content model. So we write

    <xs:complexType name="F">
      <xs:complexContent>
        <xs:restriction base="tns:E">
          <xs:sequence>
            <xs:element ref="a" minOccurs="3" maxOccurs="4"/>          
          </xs:sequence>        
        </xs:restriction>
      </xs:complexContent>
    </xs:complexType>
    

    What should the effective content model of F be here?

    Followup question

    You ask, essentially, "in that case, what’s the use of restriction?"

    Reasonable question. The answer you suggest is a good one. More generally, sometimes we find it useful to know that every instance of type B* will be an instance of type B; derivation by restriction in XSD is intended to guarantee that invariant. Sometimes it seems helpful to define an abstract type with two or more concrete restrictions; that helps ensure that the various concrete realizations of the abstract base type are nicely related to each other, even if none is a subset or superset of any other.

    There could be (no: there are plenty of) ways that derivation by restriction could be made clearer, simpler, and more convenient in XSD; not having to repeat the entire content model would be one of them. But then, that’s true for pretty much everything in XSD. Its only real virtue is that it is supported by a lot of tools a lot of people seem to want to use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a WSDL which contains the following type definition: ... <xsd:complexType name=OrderItem> <xsd:all>
Adding functionality to a class can be done by adding a method or by
My work PC has restrictions that stop me from adding programs to the start
I'm creating a site and am just adding in payments. I'm using the Paypal
I have a question regarding adding restriction in my xml schema(xsd). I have a
I have an app in which customers can partially define their schema by adding
I have my xml document containing several elements which have an attribute xml:lang. I
Adding more and more configurations to my servlet container ( Embedded Jetty in my
Adding more than one child to a WPF StatusBar results in poor layout with
Adding Exceptional Handling is a good practise, but I have a doubt, In our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.