Can anyone tell me why my output is duplicating the 'FirstNode'?
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;
class Program
{
static void Main(string[] args)
{
Root root = new Root();
FirstNode firstNode = new FirstNode();
firstNode.Data = "DATA";
root.FirstNode.Add(firstNode);
XmlSerializer s = new XmlSerializer(typeof(Root));
StringWriter sw = new StringWriter();
s.Serialize(sw, root);
string serializedXml = sw.ToString();
Console.WriteLine(serializedXml);
Console.ReadKey();
}
}
public class Root
{
List<FirstNode> firstNode = new List<FirstNode>();
public List<FirstNode> FirstNode
{
get { return firstNode; }
set { firstNode = value; }
}
}
public class FirstNode
{
string data;
public string Data
{
get { return data; }
set { data = value; }
}
}
OUTPUT
<Root>
<FirstNode>
<FirstNode>
<Data>DATA</Data>
</FirstNode>
</FirstNode>
</Root>
Expected Output
<Root>
<FirstNode>
<Data>DATA</Data>
</FirstNode>
</Root>