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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:25:15+00:00 2026-05-20T06:25:15+00:00

I asked this question yesterday, wondering how to produce XML with attributes using MVCContrib.

  • 0

I asked this question yesterday, wondering how to produce XML with attributes using MVCContrib. The answer was to use [XmlAttribute].

Since, I’ve successfully used [XmlAttribute] to get the following XML:

<?xml version="1.0" encoding="utf-8"?>
<TopTen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SectorName>Property - Direct UK</SectorName>
  <PerformanceTo>2011-01-31T00:00:00</PerformanceTo>
  <OrderedShareClassReturns>
    <OrderedShareClassReturn Name="Property L" Performance="11.074980" />
    <OrderedShareClassReturn Name="UK Property Trust I Inc" Performance="10.512610" />
    <OrderedShareClassReturn Name="UK Property Trust I Acc" Performance="10.466310" />
    <OrderedShareClassReturn Name="UK Property Trust R Inc" Performance="9.725650" />
  </OrderedShareClassReturns>
</TopTen>

Now I need to add a second <ShareClassReturns> node to the XML, and I’d like to add an attribute to that element, so the XML becomes:

<?xml version="1.0" encoding="utf-8"?>
<TopTen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <SectorName>Property - Direct UK</SectorName>
  <PerformanceTo>2011-01-31T00:00:00</PerformanceTo>
  <OrderedShareClassReturns order="top"> // how can I add the "top" & "bottom" attributes?
    <OrderedShareClassReturn Name="Property L" Performance="11.074980" />
    <OrderedShareClassReturn Name="UK Property Trust I Inc" Performance="10.512610" />
    <OrderedShareClassReturn Name="UK Property Trust I Acc" Performance="10.466310" />
    <OrderedShareClassReturn Name="UK Property Trust R Inc" Performance="9.725650" />
  </OrderedShareClassReturnss>
  <OrderedShareClassReturns order="bottom">
    <OrderedShareClassReturn Name="Property L" Performance="0.074980" />
    <OrderedShareClassReturn Name="UK Property Trust I Inc" Performance="1.512610" />
    <OrderedShareClassReturn Name="UK Property Trust I Acc" Performance="2.466310" />
    <OrderedShareClassReturn Name="UK Property Trust R Inc" Performance="3.725650" />
  </OrderedShareClassReturns>
</TopTen>

But I don’t know how to do this. The objects that I’m serializing are defined as:

public class TopTen
{

    public string SectorName { get; set; }
    public DateTime PerformanceTo { get; set; }

    public List<OrderedShareClassReturn> OrderedShareClassReturns { get; set; }
}

public class OrderedShareClassReturn
{
    [XmlAttribute]
    public string Name { get; set; }

    [XmlAttribute]
    public decimal Performance { get; set; }
}

So the question is, how can I add that attribute to the <OrderedShareClassReturns> element? Do I need to define a OrderedShareClassReturns as a class that implements a List<OrderedShareClassReturn>, and have a property called order, which has [XmlAttribute]? Or is there an easier way?

  • 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-20T06:25:15+00:00Added an answer on May 20, 2026 at 6:25 am

    To do that you’d need to add another class:

    public class ReturnsWrapper {
    
        [XmlElement("OrderedShareClassReturn")]
        public List<OrderedShareClassReturn> Items { get; set; }
    
        [XmlAttribute("order")]
        public string Order {get;set;}
    }
    

    and have:

    public class TopTen
    {
    
        public string SectorName { get; set; }
        public DateTime PerformanceTo { get; set; }
        [XmlElement("OrderedShareClassReturns")]
        public List<ReturnsWrapper> Returns { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yesterday, I asked this question and never really got an answer I was really
I asked this question yesterday got a pretty good answer but can't figure out
This question follows on from a question I asked yesterday about why using the
I asked this question yesterday, and at the time it was just what I
i asked this question yesterday but it doesnt seem to have asked properly so
Yesterday in my interview I was asked this question. (At that time I was
Yesterday, I asked this question regarding best practices for a simple information retrieval system
Yesterday I asked this general question about decimals and their internal precisions. Here is
I asked a question about different testing frameworks yesterday. This question can be found
This is linked to a question I asked yesterday. Briefly, the problem I'm having

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.