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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:07:02+00:00 2026-05-28T11:07:02+00:00

I am a xml newbie trying to create a XDocument type from a xml

  • 0

I am a xml newbie trying to create a XDocument type from a xml file.

I can validate the xml against a schema.

public class XmlHandler
{
    public XDocument Read(string filename, string schemaname)
    {
        var schemas = this.GetSchemas(schemaname);
        var doc = XDocument.Load(filename);

        var invalid = false;
        doc.Validate(schemas,
            (o, args) =>
                {
                    this.OnValidationErrors(o, args);
                    invalid = true;
                });

        return invalid ? new XDocument() : doc;
    }

    public XmlSchemaSet GetSchemas(string schemaname)
    {
        var schemas = new XmlSchemaSet();
        schemas.Add(null, schemaname);
        return schemas;
    }

    private void OnValidationErrors(object sender, ValidationEventArgs e)
    {
        Debug.Print("Errors: ", e);
    }
}

But the structure of the the XDocument seems to be wrong.

When running this code

    [Fact]
    public void Read_get_elements()
    {
        var sut = new XmlHandler();

        var result = sut.Read(this.TestFile, this.TestFileSchema);

        var root = result.Root;
        var elements = result.Elements();
        var nodes = result.Nodes();
        var descendants = result.Descendants();

        Assert.NotEmpty(elements);
    }

the root variable contains the complete xml string and the the other IEnumerable variables stay empty. What am i missing?

EDIT:
This is part of the xml and the xsd

<?xml version="1.0" encoding="UTF-8"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
       targetNamespace="https://www.eurexchange.com/members/releases/eurex14/manuals_technical_en.html" 
       xmlns="https://www.eurexchange.com/members/releases/eurex14/manuals_technical_en.html" 
       elementFormDefault="qualified">

  <xs:include schemaLocation="eurex_reports_common_structs.xsd"/>

  <xs:complexType name="cb020Type">
    <xs:annotation>
      <xs:documentation>CB020 Position Summary</xs:documentation>
    </xs:annotation>
    <xs:sequence>
      <xs:element name="rptHdr" type="rptHdrType" />
      <xs:element name="cb020Grp" type="cb020GrpType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>

  <xs:element name="cb020" type="cb020Type"/>

  <xs:complexType name="cb020GrpType">
    <xs:sequence>
      <xs:element name="cb020KeyGrp" type="cb020KeyGrpType" />
      <xs:element name="cb020Grp1" type="cb020Grp1Type" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

And this is part of the xml

<?xml version="1.0" encoding="UTF-8"?>
<cb020 xmlns="https://www.eurexchange.com/members/releases/eurex14/manuals_technical_en.html">
  <rptHdr>
    <exchNam>EUREX</exchNam>
    <envText>P</envText>
    <rptCod>CB020</rptCod>
    <rptNam>Position Summary</rptNam>
    <membLglNam>Cyberdyne Systems</membLglNam>
    <rptPrntEffDat>2011-12-05</rptPrntEffDat>
    <rptPrntRunDat>2011-12-05</rptPrntRunDat>
  </rptHdr>
  <cb020Grp>
    <cb020KeyGrp>
      ...
    </cb020KeyGrp>
    <cb020Grp1>
      ...
    </cb020Grp1>
  </cb020Grp>
</cb020>
  • 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-28T11:07:03+00:00Added an answer on May 28, 2026 at 11:07 am

    Without seeing any other way i created classes from the xsd with the wonderful tool Xsd2Code. Using a serializer i am able to get all data from the xml into an object graph. This solved my problem even if it did not answer my question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to validate an XML document against an XML Schema . The
I am a newbie and was trying to traverse a ajax loaded xml file.
I'll admit, I'm an XML newbie. I'm having trouble validating some xml against a
An XSLT-newbie problem: I need to substitute a text value in XML-file. All other
xml.etree.ElementTree.parse is choking on my xhtml file. I saw somewhere that lxml can handle
I am a newbie to OPENXML. But I am trying to load a .XML
I'm sorry, I'm a complete newbie to CSS and I'm trying to create a
Im a newbie in XML and i have some questions Can XML be used
So I'm trying to parse some XML from the twitter API and for some
I'm an XML newbie and I have an XML document (which I can't edit

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.