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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:12:39+00:00 2026-05-31T13:12:39+00:00

I’m trying to parse a custom XSD to build a list of elements which

  • 0

I’m trying to parse a custom XSD to build a list of elements which have custom attributes defined. I’ve pasted a sample node from my XSD below. In my case, I’m trying to build a list of all elements (simple and complex types) that have been marked as static. Sample –

    <xs:element name="ATestEnum">
      <xs:annotation>
        <xs:appinfo>
          <ConfigurationMemberMetadata>
            <Static>False</Static>
          </ConfigurationMemberMetadata>
        </xs:appinfo>
      </xs:annotation>
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="Sample1" />
          <xs:enumeration value="Sample2" />
        </xs:restriction>
      </xs:simpleType>
    </xs:element>

I just can’t figure out a way to query ‘inside’ an element for the properties I need. I’ve gotten as far as this –

var doc = XDocument.Load(schemaFileName);            
foreach (var element in doc.Descendants(xs + "element"))
{
    Console.WriteLine(element.Attribute("name").Value);
}

This gives me a list of all the elements in the xsd but not the specific property (ConfigurationMemberMetadata) that I need to check. I see the element.Annotation(type) method but how do I cast it to extract the fields I’m looking for?

I also tried using the XmlTextReader and reading the schema, compiling the schemaset and iterating through the elements but that doesn’t help either.

Can someone point me in the right direction? I’m very new to xml parsing and would really appreciate your help! Thanks.

  • 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-31T13:12:40+00:00Added an answer on May 31, 2026 at 1:12 pm

    You have to use something like this:

    XmlReader reader = XmlReader.Create(@"D:\....\your-file.xsd");
    XDocument doc = XDocument.Load(reader);
    XmlNamespaceManager ns = new XmlNamespaceManager(reader.NameTable);
    ns.AddNamespace("", "http://tempuri.org/XMLSchema.xsd");
    XNamespace xs = "http://www.w3.org/2001/XMLSchema";
    foreach (var element in doc.Descendants(xs + "element")) { Console.WriteLine(element.Attribute("name").Value); }
    foreach (XElement element in (IEnumerable)doc.XPathEvaluate("//ConfigurationMemberMetadata")) { Console.WriteLine(element.Name); }
    

    Annotations are not showing up in the infoset, they’re something else. To get to your element, use an XPath.

    One thing to pay attention is the namespace you associate with your prefix. Typically, in an XSD file, the default namespace matches the target namespace, which is why I’ve set a dummy namespace – update to match yours. If you don’t have a default namespace, just set the uri to the empty string as well.

    Here is the XSD I’ve used with the code above:

    <?xml version="1.0" encoding="utf-8" ?>
    <!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
    <xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="ATestEnum"> 
            <xs:annotation> 
                <xs:appinfo> 
                    <ConfigurationMemberMetadata> 
                        <Static>False</Static> 
                    </ConfigurationMemberMetadata> 
                </xs:appinfo> 
            </xs:annotation> 
            <xs:simpleType> 
                <xs:restriction base="xs:string"> 
                    <xs:enumeration value="Sample1"/> 
                    <xs:enumeration value="Sample2"/> 
                </xs:restriction> 
            </xs:simpleType> 
        </xs:element>
    </xs:schema>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.