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

  • Home
  • SEARCH
  • 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 7781011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:05:20+00:00 2026-06-01T19:05:20+00:00

I am having a heck of a time trying to parse a schema file…

  • 0

I am having a heck of a time trying to parse a schema file… was hoping someone could help.

Here is what the xsd looks like

 <xs:element name="E1">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="E2" nillable="true" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="E3" minOccurs="0" maxOccurs="unbounded">
                            <xs:complexType>
                                <xs:sequence>
                                    <xs:element name="E4" nillable="true" minOccurs="0">
                                        <xs:complexType>
                                            <xs:sequence>
                                                <xs:element name="E5" minOccurs="0" maxOccurs="unbounded">
                                                    <xs:complexType>
                                                        <xs:attribute name="A1" type="xs:integer" use="optional" />
                                                        <xs:attribute name="A2" type="xs:string" use="optional" />
                                                        <xs:attribute name="A3" type="xs:string" use="optional" />\
                                                    </xs:complexType>
                                                </xs:element>
                                            </xs:sequence>
                                        </xs:complexType>
                                    </xs:element>
                               </xs:complexType>
                            </xs:element>
                         </xs:complexType>
                     </xs:element>

This isn’t complete, but enough to get the idea. Here is the code I was trying to get the element name, followed by any attributes if they existed, but this is only returning the element names.

var xs = XNamespace.Get("http://www.w3.org/2001/XMLSchema");
var doc = XDocument.Load(sourceName + sourceApi + "Input.txt");
        foreach (var el in doc.Descendants(xs + "element"))
        {
            Trace.WriteLine("ANDY ------ " + el.Attribute("name").Value);
            foreach (var attr in el.Elements(xs + "attribute"))
            {
                Trace.WriteLine(attr.Attribute("name").Value);
            }
        }

This is outputing

Andy —– E1
Andy —– E2
Andy —– E3
Andy —– E4
Andy —– E5

Where I want it to output

Andy —– E1
Andy —– E2
Andy —– E3
Andy —– E4
Andy —– E5
A1
A2
A3

Thanks in advance.

  • 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-01T19:05:21+00:00Added an answer on June 1, 2026 at 7:05 pm

    el.Elements checks only the child elements, so there it return nothing. You should use Descendants or specify full path by el.Elements(xs + "complexType").Elements(xs + "attribute"):

    var xs = XNamespace.Get("http://www.w3.org/2001/XMLSchema");
    var doc = XDocument.Load(sourceName + sourceApi + "Input.txt");
    foreach (var el in doc.Descendants(xs + "element"))
    {
        Trace.WriteLine("ANDY ------ " + el.Attribute("name").Value);
        foreach (var attr in el.Elements(xs + "complexType").Elements(xs + "attribute"))
        {
            Trace.WriteLine(attr.Attribute("name").Value);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a heck of a time trying to get a gridview to refresh
I am having one heck of a hard time trying to figure this out.
I'm having a heck of a time trying to get a silverlight datagrid to
I am having a heck of a time with this -- I am trying
I'm having a heck of a time trying to manipulate my reports so that
I am having a heck of a time trying to get this to work.
I am having a heck of time with something that seems rather straightforward but
I am having a heck of a time taking the information in a tweet
I'm having a heck of a time getting ♥ type characters into my database
I am having a heck of a time with this one guys. I am

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.