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 8730323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:59:50+00:00 2026-06-13T08:59:50+00:00

We have a definition of Person element where we want different elements to be

  • 0

We have a definition of Person element where we want different elements to be required depending on
what they are doing. For example, if they are adding a Person, then different elements are required
to be sent versus updating a Person. Below in the example, the Person type is currently duplicated, which
of course is wrong. Is there a good way of representing this in the xsd so we can reuse the Person type.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:complexType name="Person">
        <xs:annotation>
            <xs:documentation>This is the definition when changing a person</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="PartyName" type="xs:string" minOccurs="0" maxOccurs="1"/>
            <xs:element name="GenderCode" type="GenderCode_Type" minOccurs="0" maxOccurs="1"/>
            <xs:element name="BirthDate" type="xs:date" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Person">
        <xs:annotation>
            <xs:documentation>This is the definition when adding a person</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="PartyName" type="xs:string" minOccurs="1" maxOccurs="1"/>
            <xs:element name="GenderCode" type="GenderCode_Type" minOccurs="1" maxOccurs="1"/>
            <xs:element name="BirthDate" type="xs:date" minOccurs="0" maxOccurs="1"/>
        </xs:sequence>
    </xs:complexType>   
</xs:schema>
  • 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-13T08:59:51+00:00Added an answer on June 13, 2026 at 8:59 am

    The simplest way to have two different types for Person elements is to use local declarations of Person in the two different contexts you have in mind. For example, you might say:

    <xs:element name="Add">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="Person" type="AddPerson"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    
    <xs:element name="Update">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="Person" type="ChangePerson"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    

    This example assumes that you have redefined your two complex types as AddPerson and ChangePerson.

    If additionally you want to have the two complex types be explicitly related, you can derive them both by restriction from a generic Person type.

    <xs:complexType name="Person">
      <xs:annotation>
        <xs:documentation>This is the generic 
          definition for persons</xs:documentation>
      </xs:annotation>
      <xs:sequence>
        <xs:element name="PartyName" type="xs:string" 
                    minOccurs="0" maxOccurs="1"/>
        <xs:element name="GenderCode" type="GenderCode_Type" 
                    minOccurs="0" maxOccurs="1"/>
        <xs:element name="BirthDate" type="xs:date" 
                    minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
    </xs:complexType>
    
    <xs:complexType name="ChangePerson">
      <xs:annotation>
        <xs:documentation>This is the definition 
          when changing a person</xs:documentation>
      </xs:annotation>
      <xs:complexContent>
        <xs:restriction base="Person">
          <xs:sequence>
            <xs:element name="PartyName" type="xs:string" 
                        minOccurs="0" maxOccurs="1"/>
            <xs:element name="GenderCode" type="GenderCode_Type" 
                        minOccurs="0" maxOccurs="1"/>
            <xs:element name="BirthDate" type="xs:date" 
                        minOccurs="0" maxOccurs="1"/>
          </xs:sequence>        
        </xs:restriction>
      </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="AddPerson">
      <xs:annotation>
        <xs:documentation>This is the definition 
          when adding a person</xs:documentation>
      </xs:annotation>
      <xs:complexContent>
        <xs:restriction base="Person">
          <xs:sequence>
            <xs:element name="PartyName" type="xs:string" 
                        minOccurs="1" maxOccurs="1"/>
            <xs:element name="GenderCode" type="GenderCode_Type" 
                        minOccurs="1" maxOccurs="1"/>
            <xs:element name="BirthDate" type="xs:date" 
                        minOccurs="0" maxOccurs="1"/>
          </xs:sequence>        
        </xs:restriction>
      </xs:complexContent>
    </xs:complexType>  
    

    Here, the generic type Person is identical to the AddPerson type; I’ve defined AddPerson using a vacuous restriction just for the symmetry of deriving both of the operation-specific types from the generic type.

    Whether having such an explicit relation among your types actually helps you achieve your goals will depend, of course, in part on what use your system makes of your schema type definitions.

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

Sidebar

Related Questions

I have a class Person i.e. the definition of Person with name and age.
I have a definition like this def bar(self, foo=None, bar=None, baz=None): pass I want
I have a list definition in my solution, and i want programmatically be able
I am using mongodb from C#. I have an entity definition, and I want
I have a collection of Person objects that I want to display in a
Lets say I have class definition like this (fairly simple): class Person { public
In the database, I have a definition table that is read from the application
I have a function definition of the following form (within a large code): class
I have a function definition in my VC++ Win32 DLL DEMO2_API void ProcessData(char* i_buff,
I have a typical definition/instance situation in my data modeling. I'm trying to store

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.