help with Deserialize a string problem in c#
-
:confused:I have a problem with the Deserialize a xml string. I have a object I serialize: MemoryStream buffer = new MemoryStream(); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(myobject)); xmlSerializer.Serialize(buffer, schedule); if I Deserialize the object after this code line, it works fine. But if I store the xml in code it Deserialize it gives me an error. XmlDocument doc = new XmlDocument(); doc.Load(buffer); string xml = doc.OuterXml; XmlTextReader xmlreader = new XmlTextReader(xml); schedule = (ScheduleDefinition) serializer.Deserialize(xmlreader); I need the xml string as a parameter, so i need to be able to convert it back into the object. But I always get the message: {"There is an error in XML document (1, 426)." } Any other suggestions to accomplish this? X|
-
:confused:I have a problem with the Deserialize a xml string. I have a object I serialize: MemoryStream buffer = new MemoryStream(); System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(myobject)); xmlSerializer.Serialize(buffer, schedule); if I Deserialize the object after this code line, it works fine. But if I store the xml in code it Deserialize it gives me an error. XmlDocument doc = new XmlDocument(); doc.Load(buffer); string xml = doc.OuterXml; XmlTextReader xmlreader = new XmlTextReader(xml); schedule = (ScheduleDefinition) serializer.Deserialize(xmlreader); I need the xml string as a parameter, so i need to be able to convert it back into the object. But I always get the message: {"There is an error in XML document (1, 426)." } Any other suggestions to accomplish this? X|
It sounds like your trying to serialize a string that contains xml using an xml serializer. I've never tried that before, but I have the suspicion that you might have some problems with that. Primarily, if your xml string contains the xml file header (i.e. ), and its embedded in the middle of another xml document, then you will get an error when the parser tries to read that "string". You can only have at the top of an xml document, and it can not exist anywhere else. XML inside XML might be your problem (although I can't guarantee it).