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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:53:56+00:00 2026-05-27T21:53:56+00:00

This is a generalized example of what I am up against. I have created

  • 0

This is a generalized example of what I am up against.

I have created derived types in my schema and want to create an element which is an unbounded list (sequence) which has a restrictition where only two of the three derived types is allowed.

To say it from a top level view, “I have events where in one situation can only have two types of events”.

Here is how I have defined my events and a subsequent holder of the sequence. (This all works and is valid).

The abstract item is a complex type named “Event Base” and has a common attribute called Name:

<xs:complexType name="EventBase">
   <xs:annotation><xs:documentation>***Abstract Event***</xs:documentation></xs:annotation>
   <xs:attribute name="Name"/>
</xs:complexType>

Then I have three events derived from the abstract as follows

<xs:complexType name="DerivedEvent1">
    <xs:complexContent>
        <xs:extension base="EventBase">
            <xs:attribute name="Alpha" type="xs:string"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:complexType name="DerivedEvent2">
    <xs:complexContent>
        <xs:extension base="EventBase">
            <xs:attribute name="Beta"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
<xs:complexType name="DerivedEvent3">
    <xs:complexContent>
        <xs:extension base="EventBase">
            <xs:attribute name="Gamma"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

To facilliate a complex object to hold the derived events, I create a concrete “generic” event derived from the abstract complex

<xs:element name="Event" type="EventBase">
    <xs:annotation><xs:documentation>A generic event derived from abstract.</xs:documentation></xs:annotation>
</xs:element>

Then I want to be able to hold the events, so I create a new complex object to hold the “generic” event shown above, but will actually hold derived events by the eventual consumer.

<xs:complexType name="EventsCollectionType">
    <xs:annotation><xs:documentation>Holds derived events</xs:documentation></xs:annotation>
    <xs:sequence>
        <xs:element ref="Event" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

Finally I create an element derived from the collection type which will hold actual events:

<xs:element name="Events"><xs:annotation><xs:documentation>Concrete holder of events.</xs:documentation></xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element ref="Event" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

The resulting xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Events xsi:noNamespaceSchemaLocation="file:///C:/StackOverflow.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Event xsi:type="DerivedEvent1" Name="D1" Alpha="Content1"/>
    <Event xsi:type="DerivedEvent3" Name="D1" Gamma="Content3"/>
</Events>

So the question is, how can I create a final Event*s* element which will hold only specific xsi:typed items?

So in the case where a restriction held that only the derived types of 1 and 3 would be valid (as above); but if it had a derived type 2 it would be invalid.

I have created a public GIST (Constraint or Restriction on xsi:type)

  • 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-05-27T21:53:57+00:00Added an answer on May 27, 2026 at 9:53 pm

    I may be wrong, but I don’t think this is possible.

    Within the Events collection you essentially want to have different structures but all with the same element name “Event”. This goes against a fundamental constraint of schemas: http://www.w3.org/TR/xmlschema-1/#cos-element-consistent. Using xsi:type gives the schema processor a hint that will allow it to disambiguate this choice of structures thus avoiding violating this rule. It’s essentially a work-around.

    Could you not call each different things so you have a collection of “event1″s and “event3″s or an outer collection containing a sequence of optional “events1″s and “event3″s? It would be much easier to schema enforce the structure in this way. Also then you wouldn’t require to use xsi:type at all. I’m not sure if you are using xsi:type in your instances to try to work around this limitation or for another reason but it may be easier for anybody using the schema to not have to worry about derived types.

    Alternatively, you could potentially use another technology (eg schematron) to help enforce this constraint.

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

Sidebar

Related Questions

I am working on a generalized base of a validation util which I want
Here's a generalized scenario. I have Tasks and I have Task Events. I've created
This should be a simple one: I have an observableArray object called To in
This is my sample code: SPWeb web = SPContext.Current.Web SPList list = web.Lists[TestList]; try
I have a string like this: Heading Some interesting text here HeadingSome interesting text
I have a more complicated function that I am working on. I want to
This could probably be generalized to any templated class, but I've run into this
It's probably best to explain with an example. This is an example linked from
In short: How to hash a free polyomino? This could be generalized into: How
I have a set of sentences. For each of them I want to obtain

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.