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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:06:43+00:00 2026-06-07T09:06:43+00:00

I have problems getting the Attributes of a XmlSchema sub element. There is an

  • 0

I have problems getting the Attributes of a XmlSchema sub element.

There is an abstactElement and a concreteElement which extends the abstractElement.
Getting the base’s attributes works fine using XmlSchemaComplexType.BaseXmlSchemaType.
But getting the concreteElement‘s attributes using XmlSchemaComplexType.Attributes does not work.

This is my example Xml-Schema file:

<xs:schema id="XMLSchema1"
    targetNamespace="http://tempuri.org/XMLSchema1.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/XMLSchema1.xsd"
    xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
    <xs:element name = "ConcreteElement" type="concreteElement" />

    <xs:complexType name="abstractElement">
        <xs:attribute name="aA1" type="xs:string" />
        <xs:attribute name="aA2" type="xs:string" />
        <xs:attribute name="aA3" type="xs:string" />    
    </xs:complexType>

    <xs:complexType name="concreteElement">
        <xs:complexContent>
            <xs:extension base="abstractElement">
                <xs:attribute name="cA1" type="xs:string"/>
                <xs:attribute name="cA2" type="xs:string"/>
                <xs:attribute name="cA3" type="xs:string"/>
            </xs:extension>    
        </xs:complexContent>
    </xs:complexType>
</xs:schema>

I want to get all attributes of the ConcreteElement (cA1, cA2, cA3) and all the attributes of its base element (aA1, aA2, aA3).

My code looks like that:

public Program()
{
    XmlSchema xsd =
          XmlSchema.Read(
              new StreamReader("/Path/To/My/Xsd/File.xsd"),
              null);

    var xss = new XmlSchemaSet();
    xss.Add(xsd);
    xss.Compile();

    XmlSchemaElement xsdRoot = null;
    /* Get the root element */
    foreach (DictionaryEntry curEle in xsd.Elements)
    {
        var xse = (XmlSchemaElement)curEle.Value;
        xsdRoot = xse;
        break;
    }

    List<XmlSchemaAttribute> lsAttributes = this.GetAllAttributes(
                          xsdRoot.ElementSchemaType as XmlSchemaComplexType);
    foreach (XmlSchemaAttribute curAtr in lsAttributes)
    {
        Console.WriteLine(curAtr.Name);
    }

    Console.ReadKey();
}

And this is my GetAllAttributes method:

private List<XmlSchemaAttribute> GetAllAttributes(
    XmlSchemaComplexType comCon)
{
    /* No Ancestor, no Attributes */
    if (comCon == null)
    {
        return new List<XmlSchemaAttribute>();
    }

    /* Get attributs of the acestors */
    List<XmlSchemaAttribute> allAttributes =
        this.GetAllAttributes(
            comCon.BaseXmlSchemaType as XmlSchemaComplexType);

    /* Ad the attributes of the given element */
    allAttributes.AddRange(comCon.Attributes.Cast<XmlSchemaAttribute>());

    return allAttributes;
} 

Regards,

  • 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-07T09:06:46+00:00Added an answer on June 7, 2026 at 9:06 am

    Finally the solution is to use the Property AttributeUses, which holds all the attributes
    of an element, even those which belong to the ancestors.

    private List<XmlSchemaAttribute> GetAllAttributes(
        XmlSchemaComplexType comCon)
    {        
        List<XmlSchemaAttribute> allAttributes = new List<XmlSchemaAttribute>();
    
        /* Add the attributes of the given element */
        foreach (DictionaryEntry curAttriEntry in comCon.AttributeUses)
        {
            XmlSchemaAttribute curAttri =
                curAttriEntry.Value as XmlSchemaAttribute;
    
            if (curAttri != null)
            {
                allAttributes.Add(curAttri);
            }
        }
    
        return allAttributes;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems getting some of my views aligned in a relative layout that
I'm trying out KO but have problems getting observableArray to work, the code is
I have no problems getting the Json to work and parse the json return.
I'm trying to create a SVN Eclipese EFS plugin and have problems when getting
Ever since deleting the original settings.settings file I have had endless problems getting the
I have had a few problems getting this right, so I wanted to ask
I am having problems getting my Permalinks changed with my Wordpress instance. I have
I am new to jquery mobile, and am having problems getting content I have
I have a class with attributes which have a reference to another attribute of
I have this code which getting html code of page and than replace 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.