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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:34:04+00:00 2026-05-14T03:34:04+00:00

I have a deserialized xml c# objet. I need to iterate through the oject

  • 0

I have a deserialized xml c# objet.
I need to iterate through the oject to display all items, in this case there’s just one, and display the name, colors and sizes for each item.

The xml:

<?xml version="1.0" encoding="utf-8"?>
<Catalog Name="Example">
  <Items>
    <Item Name="ExampleItem">
      <Colors>
        <Color Name="Black" Value="#000" />
        <Color Name="White" Value="#FFF" />
      </Colors>
      <Sizes>
        <Size Name="Small" Value="10"  />
        <Size Name="Medium" Value="20"  />
      </Sizes>
    </Item>
  </Items>
</Catalog>

xsd.exe generated classes:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4927
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

// 
// This source code was auto-generated by xsd, Version=2.0.50727.42.
// 


/// <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(Namespace="", IsNullable=false)]
public partial class Catalog {

    private CatalogItemsItem[][] itemsField;

    private string nameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("Item", typeof(CatalogItemsItem[]), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public CatalogItemsItem[][] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
}

/// <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)]
public partial class CatalogItemsItem {

    private CatalogItemsItemColorsColor[][] colorsField;

    private CatalogItemsItemSizesSize[][] sizesField;

    private string nameField;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("Color", typeof(CatalogItemsItemColorsColor[]), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public CatalogItemsItemColorsColor[][] Colors {
        get {
            return this.colorsField;
        }
        set {
            this.colorsField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
    [System.Xml.Serialization.XmlArrayItemAttribute("Size", typeof(CatalogItemsItemSizesSize[]), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
    public CatalogItemsItemSizesSize[][] Sizes {
        get {
            return this.sizesField;
        }
        set {
            this.sizesField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }
}

/// <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)]
public partial class CatalogItemsItemColorsColor {

    private string nameField;

    private string valueField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Value {
        get {
            return this.valueField;
        }
        set {
            this.valueField = value;
        }
    }
}

/// <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)]
public partial class CatalogItemsItemSizesSize {

    private string nameField;

    private string valueField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Name {
        get {
            return this.nameField;
        }
        set {
            this.nameField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string Value {
        get {
            return this.valueField;
        }
        set {
            this.valueField = value;
        }
    }
}

/// <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(Namespace="", IsNullable=false)]
public partial class NewDataSet {

    private Catalog[] itemsField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("Catalog")]
    public Catalog[] Items {
        get {
            return this.itemsField;
        }
        set {
            this.itemsField = value;
        }
    }
}

Deserialization code:

    System.Xml.Serialization.XmlSerializer xSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Catalog));
            TextReader reader = new StreamReader("catalog.xml");
            Catalog catalog = (Catalog)xSerializer.Deserialize(reader);
            foreach (var item in catalog.Items)
            {


            }


   reader.Close();

When I setp through the code there is one item present in catalog.items, but it is empty, no name, colors or sizes.

Any ideas what I need to do?

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-14T03:34:05+00:00Added an answer on May 14, 2026 at 3:34 am

    XSD isn’t perfect – and in this case, it definitely gets it wrong!

    In my case, I had code like this:

    public partial class Catalog {
        private CatalogItemsItem[][] itemsField;
        private string nameField;
    
        /// <remarks/>
        [XmlArray(Form=XmlSchemaForm.Unqualified)]
        [XmlArrayItem("Item", typeof(CatalogItemsItem), 
         Form=XmlSchemaForm.Unqualified, IsNullable=false)]
        public CatalogItemsItem[][] Items {
            get {
    
    
    ......    
    
    public partial class CatalogItemsItem {
        private CatalogItemsItemColorsColor[][] colorsField;
        private CatalogItemsItemSizesSize[][] sizesField;
    

    Those “arrays of arrays” are a typical error you sometimes encounter with XSD. I couldn’t even deserialize your test XML !

    Once I changed this to just simple one-dimensional arrays, everything works just fine.

    public partial class Catalog {
        private CatalogItemsItem[] itemsField;
        private string nameField;
    
        /// <remarks/>
        [XmlArray(Form=XmlSchemaForm.Unqualified)]
        [XmlArrayItem("Item", typeof(CatalogItemsItem), 
         Form=XmlSchemaForm.Unqualified, IsNullable=false)]
        public CatalogItemsItem[] Items {
            get {
    
    
    ......    
    
    public partial class CatalogItemsItem {
        private CatalogItemsItemColorsColor[] colorsField;
        private CatalogItemsItemSizesSize[] sizesField;
    

    And no, I’m sorry, I don’t know of any switch that would allow you to tell XSD to behave like this all the time – it’s manual “after-the-generation-cleanup-work” that needs to be done here.

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

Sidebar

Related Questions

I have two xml files with the same data but different tags. I need
I have an object structure I have deserialized from XML - but I'm wanting
I have this xml snippet as part of a xml file that will be
I have some Xml that I need to deserialize into an object. The Xml
I have the following xml that I need to deserialise to an object: <animals>
I have a situation where I need to store some data that just won't
I have an XML file I deserialized into an object, and now I want
I have an XML dox like this: <?xml version=1.0 encoding=utf-8?> <Server Manufacturer=SQL Version=1> <Database
I have following object structure, deseralized from XML (WS): <ns2:Category> <ns2:CategoryId>800003</ns2:CategoryId> <ns2:CategoryName>Name1</ns2:CategoryName> <ns2:Categories> <ns2:Category>
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that

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.