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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:47:04+00:00 2026-05-14T23:47:04+00:00

I am trying to read enum from a XSD file. The schema is as

  • 0

I am trying to read enum from a XSD file. The schema is as follows

 <xs:schema id="v1.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="unqualified" elementFormDefault="qualified" msdata:IsDataSet="true">   
<xs:simpleType name="Type">
     <xs:restriction base="xs:string">
      <xs:enumeration value="Op1" />
      <xs:enumeration value="Op2" />
      <xs:enumeration value="Op3" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

I also tried using this but I am getting list item count as Zero. Following is the code I am using

DataSet _sR = new DataSet();
 _sR.ReadXmlSchema(assembly.GetManifestResourceStream("v1.xsd"));
    XmlDocument xDoc = new XmlDocument();
             xDoc.LoadXml(_sR.GetXml());
             XmlNamespaceManager xMan = new XmlNamespaceManager(xDoc.NameTable);
             xMan.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");

             XmlNodeList xNodeList = xDoc.SelectNodes(
                            "//xs:schema/xs:simpleType[@name='Type']/xs:restriction/xs:enumeration", xMan);

             string[] enumVal = new string[xNodeList.Count];
             int ctr = 0;
             foreach (XmlNode xNode in xNodeList)
             {
                enumVal[ctr] = xNode.Attributes["value"].Value;
                ctr++;
             }
  • 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-14T23:47:05+00:00Added an answer on May 14, 2026 at 11:47 pm

    You can get the enumerated values by using the XmlSchema object which provides programmatic access all the elements of the xsd.

    using System.Xml;
    using System.Xml.Schema;
    

    XmlSchema schema = XmlSchema.Read(XmlReader.Create("v1.xsd"), 
        new ValidationEventHandler(ValidationCallbackOne));
    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add(schema);
    schemaSet.Compile();
    
    IEnumerable<string> enumeratedValues = schema.Items.OfType<XmlSchemaSimpleType>()
        .Where(s => (s.Content is XmlSchemaSimpleTypeRestriction) 
            && s.Name == "Type")
        .SelectMany<XmlSchemaSimpleType, string>
            (c =>((XmlSchemaSimpleTypeRestriction)c.Content)
                .Facets.OfType<XmlSchemaEnumerationFacet>().Select(d=>d.Value));
    
    // will output Op1, Op2, Op3...
    foreach (string s in enumeratedValues)
    {
        Console.WriteLine(s);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read from a file and encrypt the data using AES
When trying to read a RSA private key from a file using the method
Trying to read string from Org.BouncyCastle.Asn1.Crmf.AttributeTypeAndValue . The string value read from the AttributeTypeAndValue
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =
Im trying to read a column of String values from my DB. Im trying
Iam trying to read a binary file to memory and pass the starting address
I am trying to read in an XML file that I have saved to
I am trying to read some XML code from a website, and am having
I trying to read a value from an ArrayCollection, I use getItemAt and get
Im trying to read a whole text file with a method i created. All

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.