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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:31:31+00:00 2026-06-15T15:31:31+00:00

I have a list inside another list (a product with variants). I would like

  • 0

I have a list inside another list (a product with variants). I would like the parent list to have attributes set on it (just an id and a name).

Desired Output

<embellishments>
    <type id="1" name="bar bar foo">
        <row>
            <id>1</id>
            <name>foo bar</name>
            <cost>10</cost>
        </row>      
    </type> 
</embellishments>

Current Code

[XmlRoot( ElementName = "embellishments", IsNullable = false )]
public class EmbellishmentGroup
{
    [XmlArray(ElementName="type")]
    [XmlArrayItem("row", Type=typeof(Product))]
    public List<Product> List { get; set; }

    public EmbellishmentGroup() {
        List = new List<Product>();
        List.Add( new Product() { Id = 1, Name = "foo bar", Cost = 10m } );
    }
}

public class Product
{
    [XmlElement( "id" )]
    public int Id { get; set; }

    [XmlElement( "name" )]
    public string Name { get; set; }

    [XmlElement( "cost" )]
    public decimal Cost { get; set; }
}

Current Output

<embellishments>
    <type>
        <row>
            <id>1</id>
            <name>foo bar</name>
            <cost>10</cost>
        </row>
    </type>
</embellishments>

  • 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-15T15:31:32+00:00Added an answer on June 15, 2026 at 3:31 pm

    You need to make another class which represents the type element. Then you can add properties to it for the attributes, like this:

    [XmlRoot(ElementName = "embellishments", IsNullable = false)]
    public class EmbellishmentGroup
    {
        [XmlElement("type")]
        public MyType Type { get; set; }
    
        public EmbellishmentGroup() 
        {
            Type = new MyType();
        }
    }
    
    public class MyType
    {
        [XmlAttribute("id")]
        public int Id { get; set; }
    
        [XmlAttribute("name")]
        public string Name { get; set; }
    
        [XmlElement("row")]
        public List<Product> List { get; set; }
    
        public MyType()
        {
            Id = 1;
            Name = "bar bar foo";
            List = new List<Product>();
            Product p = new Product();
            p.Id = 1;
            p.Name = "foo bar";
            p.Cost = 10m;
            List.Add(p);
        }
    }
    
    public class Product
    {
        [XmlElement( "id" )]
        public int Id { get; set; }
    
        [XmlElement( "name" )]
        public string Name { get; set; }
    
        [XmlElement( "cost" )]
        public decimal Cost { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an unordered list that I would like to wrap inside another unordered
I have a class that holds another objects inside it (List, Set and objects
I have a list object List<Documents> , and inside that I have another list
So my idea is to have a one list than have another list inside
I want to list all controls inside another control which have names starting with
I would like to create a list variable of items from another list. So
I have a list of Persons inside a Company Class. public class Company{ IList<Person>
I have a list of images inside divs and a jquery ui slider, when
I have a navigation list I placed inside of a , I am attempting
I have a list item with a button inside. When the button is shown,

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.