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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:13:29+00:00 2026-05-13T09:13:29+00:00

I am parsing my XSD file. (including some elements, complexTypes and simpleTypes) I want

  • 0

I am parsing my XSD file. (including some elements, complexTypes and simpleTypes)

I want to detect each of them by type property.

My XSD file a little like this.

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="mainInfo">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element ref="DocumentInfo" minOccurs="1" maxOccurs="1" />
        <xsd:element ref="Prerequisite" minOccurs="1" maxOccurs="1" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <!-- Element of DocumentInfo -->
  <xsd:element name="DocumentInfo">
    <xsd:complexType>
      <xsd:attribute name="Name" type="xsd:string" />
      <xsd:attribute name="Description" type="xsd:string" />
    </xsd:complexType>
  </xsd:element>
  <!-- Element of Prerequisite -->
  <xsd:element name="Prerequisite">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Type" type="Prerequisite.Type.type" minOccurs="1" maxOccurs="1" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:complexType name="Prerequisite.Type.type">
    <xsd:attribute name="SystemType" type="SystemTypeEnum" />
  </xsd:complexType>
  <xsd:simpleType name="SystemTypeEnum">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Linux" />
    </xsd:restriction>
  </xsd:simpleType>
</xsd:schema>

My sample code below

  // Add the customer schema to a new XmlSchemaSet and compile it.
        // Any schema validation warnings and errors encountered reading or 
        // compiling the schema are handled by the ValidationEventHandler delegate.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
        schemaSet.Add("http://www.w3.org/2001/XMLSchema", "D:\\TMP\\test.xsd");
        schemaSet.Compile();

        // Retrieve the compiled XmlSchema object from the XmlSchemaSet
        // by iterating over the Schemas property.
        XmlSchema customerSchema = null;
        foreach (XmlSchema schema in schemaSet.Schemas())
        {
            customerSchema = schema;
        }



foreach (XmlSchemaElement element in customerSchema.Elements.Values)
{
    XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;
     // currently, i detect my ComplexType via the method below. 
     if (aSchemaType.TypeCode == XmlTypeCode.None)
     {
     // Insert some code to handle ComplexType obj
        // Handle Elements of XSD File
        foreach (XmlSchemaElement element in customerSchema.Elements.Values)
        {
            XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType;
            Dictionary<string, object> aTempDict = new Dictionary<string,object>();

            mainDict.Add(element.Name, aTempDict);
            //Parse elements
            parseElement(complexType, ref aTempDict);
            break;
        }
     }

     // i want to find a method to detect my SimpleTYpe
     // a little like this way, but i don't want to compare the equal or not with some string value. (NO == "string", thanks.)
     else if (attribute.AttributeSchemaType.TypeCode == ???)
     // else if (Some other method to detect SimpleType in a XSD file)
    {
         // Insert some code to handle SimpleType obj
         // Loop the XSD Node and find out all the SimpleTye objects(members and type values), then add them to the related sub Dictionary based on ComplexType elements **TYPE** defined.
    }
}

How to detect the type of attribute is SimpleType with the it’s property OR other good expression?

  • 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-13T09:13:30+00:00Added an answer on May 13, 2026 at 9:13 am

    If you are just trying to parse the schema then you should take a look at this code sample from the tutorial How Do I…Use the Xml Schema Object Model?. (I did notice that the restriction is not fully implemented — it doesn’t get the restriction base type or any facets.)

    Applying to your code sample would give something like this:

        // Add the customer schema to a new XmlSchemaSet and compile it.
        // Any schema validation warnings and errors encountered reading or 
        // compiling the schema are handled by the ValidationEventHandler delegate.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
        schemaSet.Add("http://www.w3.org/2001/XMLSchema", "D:\\TMP\\test.xsd");
        schemaSet.Compile();
    
        // Retrieve the compiled XmlSchema object from the XmlSchemaSet
        // by iterating over the Schemas property.
        XmlSchema customerSchema = null;
        foreach (XmlSchema schema in schemaSet.Schemas())
        {
            customerSchema = schema;
        }
    
        // Iterate over all schema items
        foreach (object item in xmlSchema.Items)
        {
            if (item is XmlSchemaAttribute)
            {
            }
            else if (item is XmlSchemaComplexType)
            {
            }
            else if (item is XmlSchemaSimpleType)
            {
                XmlSchemaSimpleType simpleType = item as XmlSchemaSimpleType;
                Console.WriteLine("SimpleType found with name=" + simpleType.Name);
            }
            else if (item is XmlSchemaElement)
            {
            }
            else if (item is XmlSchemaAnnotation)
            {
            }
            else if (item is XmlSchemaAttributeGroup)
            {
            }
            else if (item is XmlSchemaNotation)
            {
            }
            else if (item is XmlSchemaGroup)
            {
            }
            else
            {
                Console.WriteLine("Not Implemented.");
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You might find Docsplit useful: Docsplit is a command-line utility… May 13, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer I don't know if there's a way to target the… May 13, 2026 at 8:42 pm
  • Editorial Team
    Editorial Team added an answer No, there isn't. The simplest solution is to write your… May 13, 2026 at 8:42 pm

Related Questions

I have a very large XML file that I need to parse so I
I was trying to add the XML schema to an existing EJB project. JAXB
i am using jwsc to build my webservices application. This produces a war file
I have an application that is running Jaxb 2.1.12. I am running JDK 1.5
When I configure method security under Spring Security I get the error shown above

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.