XmlSerializer Correction

I mentioned in episode 23 XMl Inside Out that there was no attribute in .NET that would flatten a collection. Raymond and I stumbled upon just such an attribute accidentally.

The issue was that all legs of a flight were direct sub elements of the "Flight" element. Serializing an array puts all of those legs under an intemediate "Legs" element. However, if you use the attribute [XmlElement("Leg")] instead of [XmlArray("Legs")], you will get a flat collection.

The point is still valid, however, that you will find some schemas that you cannot match with XmlSerializer. It was designed to be really easy, not really flexible. These two goals are often at odds with one another.

Leave a Reply

You must be logged in to post a comment.