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

  • Home
  • SEARCH
  • 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 217535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:39:59+00:00 2026-05-11T18:39:59+00:00

I’m trying to create a tool that can generate XSDs for the XAML produced

  • 0

I’m trying to create a tool that can generate XSDs for the XAML produced by serializing a type in .NET, but this is not specifically .NET related.

Let’s say I have a type. This type has properties and is a collection.

public class MyType : Collection<CollectedType>
{
  public PType1 PropertyOne {get;set;}
  public PType2 PropertyTwo {get;set;}
}

This serializes to the following (omitting the object graph construction):

<MyType xmlns="clr-namespace:blahblahblah">
  <CollectedType name="First instance in the collection"/>
  <CollectedType name="Second instance in the collection"/>
  <MyType.PropertyOne>
    <PType1 Value = "Serialized object in PropertyOne" />
  </MyType.PropertyOne>
  <MyType.PropertyTwo>
    <PType2 Value = "Serialized object in PropertyTwo" />
  </MyType. PropertyTwo >
</MyType>

In generating the XSD for this type, I can say the following:

  • MyType is a complexType
  • MyType will contain a reference to a group called CollectedTypeGroup
    • CollectedTypeGroup contains CollectedType’s element and elements for types that extend CollectedType
  • MyType will contain an element called MyType.PropertyOne
    • PType1 is another complexType
  • MyType will contain an element called MyType.PropertyTwo
    • PType2 is another complexType

This is all relatively easy to do. Here’s a chunk of the generated xsd:

  <xs:complexType name="MyType">
    <xs:sequence>
      <xs:element name="MyType.PropertyOne" type="PType1"/>
      <xs:element name="MyType.PropertyOne" type="PType1"/>
      <xs:group ref="CollectedTypeGroup"/>
    </xs:sequence>
  </xs:complexType>

Now comes the hard part. Because the XML will be mapped back to an object graph, I have a list of restrictions on how elements are added to MyType that MUST BE enforced by the schema. If these three requirements and only these three are not enforced, I face issues with users attempting to use my schema:

1) Elements added to MyType must not be restricted to a particular order
2) Elements that represent a property of my object can only appear once or not at all
3) Group elements must be unbounded; they can appear anywhere in the parent element and 0…* times

This is where I am having a horrendous time. I cannot find a satisfactory combination of choices, sequences, alls etc. to satisfy these three requirements. I have also tried placing the elements in a separate group, complexTypes, etc. Nothing seems to work.

How can I combine my elements and my groups into a single complexType and meet my three requirements?

  • 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-11T18:40:00+00:00Added an answer on May 11, 2026 at 6:40 pm

    This has puzzled people for years, but it is not possible to define this content model in XML Schema.

    The only schema particle that guarantees that your elements appears once or not at all, and in any order is xsd:all. However, as you will have probably discovered already, the maximum bound for elements in xsd:all is 1, not unbounded.

    If you had a container element for your collection elements, you could get away with this:

    <xs:complexType name="MyType">
        <xs:sequence>
          <xs:element name="MyType.PropertyOne" type="PType1" minOccurs="0"/>
          <xs:element name="MyType.PropertyTwo" type="PType2" minOccurs="0"/>
          <xs:element name="collection" type="CollectionType" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CollectionType">
        <xs:sequence>
           <xs:group ref="CollectedTypeGroup"/>
        </xs:sequence>
    </xs:complexType>
    

    Extracting things into groups, complex types, and so on, will not help you work around this problem as the Schema processor will flatten it to perform its validation.

    FYI, Relax NG does not have this limitation. You can use its “interleave” construct to define what you are looking for (it’s the same as schema ‘all’ but allows unbounded children).

    Hope this helps.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.