I need to serialize to an array which has multiple non-nested values i.e.
<MyArray>
<Code>code1</Code>
<Name>name associated with code 1</Name>
<Code>code2</Code>
<Name>name associated with code 2</Name>
<Code>code3</Code>
<Name>name associated with code 3</Name>
<Code>code4</Code>
<Name>name associated with code 4</Name>
</MyArray>
I’ve tried various attributes on my array – e.g.
[XmlArray(ElementName="MyArray")]
[XmlArrayItem(ElementName="")]
public List<MyPair> MyPairs { get; set; }
NB: the MyPair object contains 2 string properties (Code & Name):
but to no avail, I always get a containing element for each pair (which would normally be better but not what the schema demands – and over which I’ve no control). Any help greatly appreciated.
EDIT This is part of a huge xml document, is it possible to use manual serialization of XElement for 1 part of it and XMLSerialization for the rest?
Just to close this off. I worked around the problem with I think what could be called a bit of a hack as I wanted avoid serializing the entire object graph manually. So: