Re: XML Deserialization Newbie Question
- From: "Jared Parsons [MSFT]" <jaredpar@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 09:21:29 -0700
Try adding a call to writer.Flush() just before you reset the stream
position to 0
--
Jared Parsons [MSFT]
jaredpar@xxxxxxxxxxxxxxxxxxxx
http://blogs.msdn.com/jaredpar
"This posting is provided "AS IS" with no warranties, and confers no rights"
"Bill Henning" <please @ nospamforactiprosoftware.com> wrote in message
news:el%23CZZzSFHA.3184@xxxxxxxxxxxxxxxxxxxxxxx
> Hi there.... I'm trying to figure out how to do simple XML serialization
> however whenever I try to deserialize from XML, I get a System Error
> ("System.Xml.XmlException: The root element is missing.").
>
> Could someone try running this sample code to tell me what I'm doing
> wrong? I'm just serializing an int and trying to call CanDeserialize on it
> and that's where the exception occurs. Thanks so much in advance!
>
>
> // ----------------------------------------------------
> string xml;
> int c = 100;
> {
> System.Xml.Serialization.XmlSerializer serializer = new
> System.Xml.Serialization.XmlSerializer(c.GetType());
> System.IO.MemoryStream stream = new System.IO.MemoryStream();
> System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream,
> null);
> serializer.Serialize(writer, c);
> stream.Position = 0;
> xml = new System.IO.StreamReader(stream).ReadToEnd();
> stream.Close();
> }
> Console.WriteLine(xml);
> {
> System.Xml.Serialization.XmlSerializer serializer = new
> System.Xml.Serialization.XmlSerializer(c.GetType());
> System.IO.MemoryStream stream = new System.IO.MemoryStream();
> System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(stream,
> null);
> writer.WriteRaw(xml);
> stream.Position = 0;
> System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(stream);
> Console.WriteLine(serializer.CanDeserialize(reader));
> }
> return;
> // ----------------------------------------------------
>
>
.
- Prev by Date: Re: Destructors are useless?
- Next by Date: Re: MultiThreading an ActiveX DLL call...
- Previous by thread: Double and Parse
- Next by thread: Easy way to copy a Dictionary<string, object> ?
- Index(es):
Relevant Pages
|