Can't seem to deserialize very simple xml using XmlSerializer in c# -
i feel going made. have written hundred deserializing routines, 1 killing me!
below returned service. simple array of strings...i think.
<arrayofstring xmlns="http://schemas.microsoft.com/2003/10/serialization/arrays" xmlns:i="http://www.w3.org/2001/xmlschema-instance"> <string>action & adventure</string> <string>comedy</string> <string>drama</string> <string>family</string> <string>horror</string> <string>independent & world</string> <string>romance</string> <string>sci-fi/fantasy</string> <string>thriller & crime</string> </arrayofstring>
i using out box deserializing
var serializer = new xmlserializer(typeof(list<string>)); var reader = new stringreader(xmlstring); var genrelist = (list<string>)serializer.deserialize(reader);
but following error on deserialize line:
<arrayofstring xmlns='http://schemas.microsoft.com/2003/10/serialization/arrays'> not expected
i have tried including namespace , creating manner of exotic objects in attempt work. crazy amount of time. in end have requested in json , deserialised json.net.
however curious have been doing wrong!
the xml serializer cannot deserialize simpletype or list of simple types without additional specification, datacontractreader can:
string content = @" <arrayofstring xmlns=""http://schemas.microsoft.com/2003/10/serialization/arrays"" xmlns:i=""http://www.w3.org/2001/xmlschema-instance""> <string>action & adventure</string> <string>comedy</string> <string>drama</string> <string>family</string> <string>horror</string> <string>independent & world</string> <string>romance</string> <string>sci-fi/fantasy</string> <string>thriller & crime</string> </arrayofstring>"; var serializer = new datacontractserializer(typeof(string[])); var reader = new xmltextreader(new stringreader(content)); var genrelist = new list<string>((string[])serializer.readobject(reader));
Comments
Post a Comment