Deseralize an array of objects
-
How can I have XmlSerializer.Deserializer deserialize an array of Category objects? Right now it'll only work on a single Category object. − 1 2 Traffic Alerts − 1 1 News Alerts − 1 3 testing category − 1 7 curl test − 1 8 sapce test
Assuming that "categories" is your root XML element, then you can do the following:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;namespace WindowsApplication1 {
[XmlRoot("categories")]
public class categories : List<category> {
}
}When building your XmlSerializer, you need to specify "categories" as the type like so:
XmlSerializer xs = new XmlSerializer(typeof(categories));
-- modified at 11:59 Monday 1st October, 2007 -- Had to escape out <
Take care, Tom ----------------------------------------------- Check out my blog at http://tjoe.wordpress.com