views:

38

answers:

2

Hello All ,

I have The Following Structure

public class GraphData
    {
        private List<RecordPerDay> recordPerDay;

        public List<RecordPerDay> RecordPerDay
        {
            get { return recordPerDay; }
            set { recordPerDay = value; }
        }
    }


public class RecordPerDay
    {
        private string date;
        private List<Entry> entry;

        [XmlAttribute]
        public string Date
        {
            get { return date; }
            set { date = value; }
        }

        public List<Entry> Entry
        {
            get { return entry; }
            set { entry = value; }
        }
    }

The Previous code Generate The following XML

<GraphData>  
    <RecordPerDay>    

    <RecordPerDay Date="9/29/2010">      
     <Entry>        
      <Entry From="08:46:07" To="20:47:06" TypeId="1" /> 
      <Entry From="08:52:21" To="08:53:17" TypeId="1" />   
      <Entry From="09:00:00" To="14:00:00" TypeId="1" />    
     </Entry>    
    </RecordPerDay>    

    <RecordPerDay Date="9/30/2010"> 
       <Entry>        
        <Entry From="08:46:07" To="20:47:06" TypeId="1" />
        <Entry From="08:52:21" To="08:53:17" TypeId="1" />  
       </Entry>    

    </RecordPerDay>  

    </RecordPerDay>
</GraphData>

but I need it to be in the following format

<GraphData>  
    <RecordPerDay Date="9/29/2010">      
      <Entry From="08:46:07" To="20:47:06" TypeId="1" /> 
      <Entry From="08:52:21" To="08:53:17" TypeId="1" />   
      <Entry From="09:00:00" To="14:00:00" TypeId="1" />    
    </RecordPerDay>    
    <RecordPerDay Date="9/30/2010"> 
        <Entry From="08:46:07" To="20:47:06" TypeId="1" />
        <Entry From="08:52:21" To="08:53:17" TypeId="1" />  
    </RecordPerDay>  
</GraphData>

Please Help me as soon as possible

Thanks in Advance

+2  A: 

Try decorating the RecordPerDay and Entry properties with [XmlElement]:

[XmlElement]
public List<RecordPerDay> RecordPerDay
{
    get { return recordPerDay; }
    set { recordPerDay = value; }
}

...

[XmlElement]
public List<Entry> Entry
{
    get { return entry; }
    set { entry = value; }
}
Darin Dimitrov
Will it not create two nested RecordPerDay??
Aliostad
@Aliostad, no it won't.
Darin Dimitrov
+1. Didn't know that.
Aliostad
A: 

Add [XmlElement] above the public List<Entry> Entry and public List<RecordPerDay> RecordPerDay

SwDevMan81