XML generation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gyanendar
    New Member
    • Jun 2007
    • 90

    XML generation

    Hi Guys,
    I want to generate xml like:
    Code:
    <View>
      <ID>1020</ID>
      <NameList>
         <Name>N1</Name>
         <Name>N1</Name>
      </NameList>
    <View>
    My Classes are :

    Code:
    public class NameList
        {
            public string Name;
        }
    
    public class View
        {
            private string ID;
            private NameList[] nameList;
            [XmlElement("ID", typeof(string))]
            public string ID
            {
                get { return ID}
                set { ID= value; }
            }
            [XmlElement("NameList", typeof(NameList))]
            public NameList[] NameList
            {
                get { return nameList; }
                set { nameList = value; }
            }
        }
    
     XmlSerializer serializer = new XmlSerializer(typeof(View));
    I am getting xml as:
    Code:
    <View>
      <ID>1020</ID>
      <NameList>
         <Name>N1</Name>
      </NameList>
      <NameList>
         <Name>N1</Name>
      </NameList>
    <View>
    Please help in fixing this.

    Thanks,
Working...