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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:28:16+00:00 2026-06-09T20:28:16+00:00

I have a situation where we have a base class which several subclasses implement.

  • 0

I have a situation where we have a base class which several subclasses implement. The base class is used to force subclasses to contain certain properties that the system requires.

Anyways, I’d like to programmatically generate XSDs for the subclasses, but I would like the properties of the base class to appear in the subclass XSD, because the base class is used for internal reasons and wouldn’t really have meaning to the client.

For example, currently if I have:

class Foo {
    public string Id { get; set; }
}

class Bar : Foo {
    public string Name { get; set; }
}

And I run that through the following code:

private string ExtractXsdFromType()
{
    Type type = typeof(Bar);
    XmlReflectionImporter importer = new XmlReflectionImporter();
    XmlTypeMapping mapping = importer.ImportTypeMapping(type);
    XmlSchemas xmlSchemas = new XmlSchemas();
    XmlSchemaExporter xmlSchemaExporter = new XmlSchemaExporter(xmlSchemas);
    using (var writer = new StringWriter())
    {
        xmlSchemaExporter.ExportTypeMapping(mapping);
        xmlSchemas[0].Write(writer);
        return XElement.Parse(writer.ToString()).ToString();
    }
}

Then it will produce an XSD like this:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Bar" nillable="true" type="Bar" />
  <xs:complexType name="Bar">
    <xs:complexContent mixed="false">
      <xs:extension base="Foo">
        <xs:sequence>
          <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  <xs:complexType name="Foo" abstract="true">
    <xs:attribute name="Id" type="xs:int" use="required" />
  </xs:complexType>
</xs:schema>

But I would like to create an XSD like this:

<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Bar" nillable="true" type="Bar" />
  <xs:complexType name="Bar">
    <xs:complexContent mixed="false">
      <xs:sequence>
        <xs:attribute name="Id" type="xs:int" use="required" />
        <xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
      </xs:sequence>
    </xs:complexContent>
  </xs:complexType>
</xs:schema>

Does anyone know if this is possible?

  • 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-09T20:28:17+00:00Added an answer on June 9, 2026 at 8:28 pm

    I would be extremely surprised to actually see this possible the way you described simply because to do it like so would break things from an Object Orientation perspective, at least most of the time. For example, if a class uses a property of a type, then in OO any class extending that type would be allowed instead.

    Collapsing the class hierarchy (which is what you describe if I understood correctly), would make it impossible to correctly create an XSD model. There would be limitations even when trying to do so from an XSD refactoring perspective, particularly where abstract types get involved, or substitution groups (I am talking in general).

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

Sidebar

Related Questions

Here's the situation. I have a base class which implements a method that accepts
I have a base class Foo that is concrete and contains 30 methods which
My situation I have an entity model with a base class ItemBase which defines
Let me explain you my situation. I have a base class called Shape, and
I have a code base that deals with simulation of certain data. It involves
I have a stateless, abstract base class from which various concrete classes inherit. Some
I have an custom UIVIewController that is the base class for other controllers and
So I have the following situation. I have a class DataTypes which has the
Ok, situation: I am using a library that I have no control over, which
I have a base class, A , and two subclasses, B and C .

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.