XML serialization query
Posted
by David Neale
on Stack Overflow
See other posts from Stack Overflow
or by David Neale
Published on 2010-06-11T08:28:05Z
Indexed on
2010/06/11
8:43 UTC
Read the original article
Hit count: 651
I have the following XML which needs deserializing/serializing:
<instance>
<dog>
<items>
<item>
<label>Spaniel</label>
</item>
</items>
</dog>
<cat>
<items>
<item>
<label>Tabby</label>
</item>
</items>
</cat>
</instance>
I cannot change the XML structure.
I need to map this to the following class:
[Serializable, XmlRoot("instance")]
public class AnimalInstance
{
public string Dog { get; set; }
public string Cat { get; set; }
}
I'm not really sure where to start on this one without manually parsing the XML. I'd like to keep the code as brief as possible. Any ideas? (and no, my project doesn't actually involve cats and dogs).
© Stack Overflow or respective owner