I'm trying to get to this result while serializing XML:
<Root Name="blah">
<SomeKey>Eldad</SomeKey>
<Element>1</Element>
<Element>2</Element>
<Element>3</Element>
<Element>4</Element>
</root>
Or in other words - I'm trying to contain an array within the "root" element, alongside additional keys.
This is my crude attempt:
[XmlRootAttribute(ElementName="Root", IsNullable=false)]
public class RootNode
{
[XmlAttribute("Name")]
public string Name { get; set; }
public string SomeKey { get; set; }
[XmlArrayItem("Element")]
public List<int> Elements { get; set; }
}
And my serialization:
string result;
XmlSerializer serializer = new XmlSerializer(root.GetType());
StringBuilder sb = new StringBuilder();
using (StringWriter sw = new StringWriter(sb))
{
serializer.Serialize(sw, root);
result = sw.ToString();
}
However, this is my result (Removed the namespace for clarity):
<Root>
<SomeKey>Eldad</SomeKey>
<Elements>
<Element>1</Element>
<Element>2</Element>
<Element>3</Element>
</Elements>
</Root>
Is there any way to remove the "Elements" part?