I'm new to XmlSerializer, I have a List<T> that I'd like to serialize like this:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<itens>
<Item corret="0" order="�)">
foo
</Item>
<Item corret="1" order=")">
baa
</Item>
</itens>
</ArrayOfItem>
instead of this (current output):
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Item corret="0" order="�)">
<test>foo</test>
</Item>
<Item corret="1" order=")">
<test>baa</test>
</Item>
</ArrayOfItem>
i.e, remove the test tag, move its contents to item and place all the items in the list inside the itens tag. How do I do this?
The class:
[Serializable]
public class Item
{
[XmlIgnore]
public int correctIndex { get; set; }
[XmlIgnore]
public int index { get; set; }
[XmlAttribute("corret")]
public string IsCorrect
{
get { return correctIndex == index ? "1" : "0"; }
set { }
}
[XmlAttribute("order")]
public string Order
{
get { return string.Format("{0})", ((char)index).ToString()); }
set { }
}
[XmlElement("test")]
public string text { get; set; }
}
I'm serializing using this:
new XmlSerializer(typeof(List<Item>)).Serialize(Console.Out, list);