views:

8

answers:

1

I am working on making a custom section of my app.config and web.config to read a configuration in. I'm following the code at http://consultingblogs.emc.com/pauloreichert/archive/2005/05/31/1514.aspx for my sample. The problem is, my config file generates as follows:

<configSections>
    <section name="BizDays" type="Holidays.BizDaysSection, Holidays, Version=1.0.3883.29809, Culture=neutral, PublicKeyToken=null" />
</configSections>
<BizDays>
  <Holidays>
    <Holiday Name="New Years Day" Day="1" Month="1" />
    <Holiday Name="MLK Day" Month="1" DayOfWeek="1" WeekOfMonth="3" />
  </Holidays>
</BizDays>

What i am wanting is code like this:

<BizDays>
  <Holidays>
    <Holiday Name="New Years Day">
      <Day>1</Day>
      <Month>1 </Month>
    </Holiday>
    <Holiday Name="MLK Day">
      <Day>1</Day>
      <DayOfWeek>1</DayOfWeek>
      <WeekOfMonth>3</WeekOfMonth>
    </Holiday>
  </Holidays>
</BizDays>

None of the examples I can find online show how to do this.

A: 

Without reading the doc you have linked to, Name appears to be correctly specified as an XMLAttribute. Day, DayOfWeek, etc, should be XMLElements.

For example, creating an instance of the following class and serializing it would yield the result you are after:

public class Holiday
{
    [XmlAttribute]
    public string Name;
    [XmlElement]
    public int Day;
    [XmlElement]
    public int Month;
}

Since XmlElement is the default, it could be left off.

Lachlan