Deserializing different named xml nodes

Posted by Andreas on Stack Overflow See other posts from Stack Overflow or by Andreas
Published on 2010-06-09T07:56:03Z Indexed on 2010/06/09 8:32 UTC
Read the original article Hit count: 192

Filed under:
|
|

Hi.

Is there a way to convert different named xml nodes into one class when deserializing an XML

Example XML:

<items>
    <aaa>value</aaa>
    <bbb>value</bbb>
</items>

Normaly i would write:

[XmlRoot("items")]
class Items
{
    [XmlElement("aaa")]
    public string aaa;

    [XmlElement("bbb")]
    public string bbb;
}

But now i would like to do something like this

[XmlRoot("items")]
class Items
{
    [XmlElement("aaa")]
    [XmlElement("bbb")]
    public List<string> item;
}

Here I would love if "aaa" and "bbb" was added to the same list.

© Stack Overflow or respective owner

Related posts about Xml

Related posts about serialization