Search code examples
c#xmlserializationdatacontract

DataContract/DataMember multiple elements in xml


I have an XML like this:

<data>
    <foo>some value</foo>
    <result>...</result>
    <result>...</result>
    <result>...</result>
    ...
</data>

I would like to deserialize it with DataContract/DataMember.. I know how to handle the array/collection of results elements if they were embedded inside a parent object like:

    <data>
    <foo>some value</foo>
    <collectionOfResults>
            <result>...</result>
            <result>...</result>
            <result>...</result>
            ...
    </collectionOfResults>
    </data>

But I don't know how to do it without the embedding element. Do you?


Solution

  • If you need to control the format of the XML, then you don't want to use the DataContractSerializer. Use the XML Serializer instead.