I have a class that, among other properties, has a list of MyObject.
public class MyClass
{
...
[XmlArray("OBJECT")]
public List<MyObject> Objects { get; set; }
...
}
Each MyObject has two properties, PropA and PropB.
public class MyObject
{
public string PropA {get;set;}
public string PropB {get;set;}
}
The XML Serializer returns this XML:
<OBJECT>
<MyObject>
<PropA>A1</PropA>
<PropB>B1</PropB>
</MyObject>
<MyObject>
<PropA>A2</PropA>
<PropB>B2</PropB>
</MyObject>
<MyObject>
<PropA>A3</PropA>
<PropB>B3</PropB>
</MyObject>
</OBJECT>
My given requirements are for it to look like this (I swear, it looks much less wrong given the real object names and property values, but regardless, this is my task):
<OBJECT>
<PropA>A1</PropA>
<PropB>B1</PropB>
<PropA>A2</PropA>
<PropB>B2</PropB>
<PropA>A3</PropA>
<PropB>B3</PropB>
</OBJECT>
What is the best way to make this happen? I tried messing around with various Xml attributes (e.g. XmlArrayItem, XmlElement), but I can't seem to get rid of the class name wrapper.
I have considered custom xml serialization, but I hate to throw away all the (working) default Xml serialization that happens on the other properties with only an XmlElement attribute on each of them.
Any thoughts?
Thank you.
EDIT: This is not a duplicate if you are referring to the link that xDaevax kindly posted. (XML Serialization - Disable rendering root element of array). This question/answer isn't asking/solving how to get rid of the item class names (the tags around each item in the list), it shows how to get rid of the overall list tag that encompasses the entire list of items. I want precisely the reverse. If there is another link to a similar, answered question, I would love to know. Thank you.