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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:21:17+00:00 2026-05-13T09:21:17+00:00

I am an XML beginner, using C# .NET 2.0/Visual Studio 2005. What I have

  • 0

I am an XML beginner, using C# .NET 2.0/Visual Studio 2005.

What I have is a data sample in XML that I’d like to convert into strongly typed data structures. I also have an XSD for that file that I ran through the Visual Studio xsd.exe to generate the code for it. I ran it against System.Xml.Serialization.XmlSerializer It did a decent job but it needs some tweaking.

Running a test against it using this code:

static int Main() {
    System.IO.StreamReader str = new System.IO.StreamReader(
        @"C:\xmlstm-2009122816413365.xml");
    System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(AidStatements));
    AidStatements statementDataSet = (AidStatements)xSerializer.Deserialize(str);

    foreach (AssocRecord associations in statementDataSet.AssocRecords) {
        foreach (statementrecord statement in associations.statementrecord) {
            Console.WriteLine(statement.acctno);
        }
    }

    str.Close();

    Console.ReadLine();

    return 0;
}

Where the test code simply prints out the account number from each record.

The problem is that the generated code is ignoring one half of the records in the file. It has to do with the <Assoc-Record> element, I think.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="Aid-Statements">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" ref="Assoc-Record"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="Assoc-Record">
    <xs:complexType>
        <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="statement-record"/>
        </xs:sequence>
    </xs:complexType>
    </xs:element>
    <xs:element name="statement-record">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="assoc-no"/>
                <xs:element ref="acct-no"/>
                <xs:element ref="acct-no-mask"/>
                <xs:element ref="member-no"/>
                <xs:element ref="cr-code"/>
                <xs:element ref="stm-bal-fwd-date"/>
                <xs:element ref="stm-close-date"/>
                <xs:element ref="stm-due-date"/>
                <xs:element ref="prop-address-info"/>
                <xs:element ref="own-mail-info"/>
                <xs:element ref="messages"/>
                <xs:element ref="balances"/>
                <xs:element ref="trx-detail"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    ...

The generated code from xsd.exe is this (a snippet):

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute("Aid-Statements", Namespace="", IsNullable=false)]
public partial class AidStatements {

    private statementrecord[] assocRecordField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute("Assoc-Record")]
    [System.Xml.Serialization.XmlArrayItemAttribute("statement-record", typeof(statementrecord), IsNullable=false)]
    public statementrecord[] AssocRecord {
        get {
            return this.assocRecordField;
        }
        set {
            this.assocRecordField = value;
        }
    }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute("statement-record", Namespace="", IsNullable=false)]
public partial class statementrecord {
    private string assocnoField;
    private string acctnoField;
    private string acctnomaskField;
    private string membernoField;
    private string crcodeField;
    private string stmbalfwddateField;
    private string stmclosedateField;
    private string stmduedateField;
    private propaddressinfo propaddressinfoField;
    private ownmailinfo ownmailinfoField;
    private messages messagesField;
    private balances balancesField;
    private trxrecord[] trxdetailField;
    // Matching properties below this
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute("Assoc-Record", Namespace="", IsNullable=false)]
public partial class AssocRecord {

    private statementrecord[] statementrecordField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("statement-record")]
    public statementrecord[] statementrecord {
        get {
            return this.statementrecordField;
        }
        set {
            this.statementrecordField = value;
        }
    }
}

It looks like xsd.exe is incorrectly assuming something about <Assoc-Record>, but nothing I’ve tried so far has helped. Trying to set <Assoc-Record> as an array attribute (as best as I could figure out) yielded no results; the code runs but <Assoc-Record> does not contain any <statement-record> elements (hows a zero-length array).

Also, xsd.exe at first turned AidStatements.assocRecordField into a 2D array, which I changed to a 1D array to get it to run in the current state.

Any ideas?

  • 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-13T09:21:18+00:00Added an answer on May 13, 2026 at 9:21 am

    The AidStatements class should look like this:

    public partial class AidStatements
    {
      [XmlElement("Assoc-Record")]
      public AssocRecord[] AssocRecords;
    }
    

    The XSD schema looks quite confusing – instead of sequences containing elements of certain type the sequences contain references to a element and this probably confuses xsd.exe (all those XmlTypeAttribute(AnonymousType=true) look weird).

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

Sidebar

Ask A Question

Stats

  • Questions 348k
  • Answers 348k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Java Strings are unicode. sb += '\u00E9'; # lower case… May 14, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer In this case I will do something like: # Import… May 14, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer You can't map a linking table with the automapping if… May 14, 2026 at 6:32 am

Related Questions

During my apprenticeship, I have used NHibernate for some smaller projects which I mostly
I am a beginner to iPhone App development. Please help me out. In my
I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using
I am a beginner in ASP.Net. I am starting a new project using ASP.Net
Note: I'm using Zend Framework, but I think most of this applies to PHP

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.