EDN Admin
Well-known member
I am trying to deserialize an xml file into a object but I am running into problems and cant seem to figure out what the problem is. I have seen this problem in the past but cant remember what I did to solve it.<br/><br/>I generated and xsd from the xml file by using the XSD.exe tool and then from the xsd I generated the typed class.<br/><br/>I can serialize the class without any issues, but when I try to deserialize it, I get an error saying: "There is an error in XML document (1, 1)."<br/>The inner exception: "Data at the root level is invalid. Line 1, position 1."<br/><br/>The xml file looks like this:<br/>
<div style="background-color:white;color:black
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue utf-8<span style="color:black " <span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 GameReminders<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Reminder<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 PostponeDatetime<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PostponeDatetime<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Games<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Games<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Dismessed<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Dismessed<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Reminder<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 GameReminders<span style="color:blue >
[/code]
<br/>The code I use to deserialize the xml file looks like this (nothing new...):<br/><br/>
<div style="background-color:white;color:black
<pre>XmlSerializer serializer = <span style="color:blue new XmlSerializer(<span style="color:blue typeof(GameReminders));
TextReader textReader = <span style="color:blue new StreamReader(<span style="color:blue new MemoryStream(Encoding.UTF8.GetBytes(xmlString)));
GameReminders settings = (GameReminders)serializer.Deserialize(textReader);
textReader.Close();
textReader.Dispose();
[/code]
<br/>Now most probably if you the reader of this post is going to try it, it will work, but it does not work here and Im stuck because I cant continue if this does work!<br/><br/>Thanks!
View the full article
<div style="background-color:white;color:black
<pre><span style="color:blue <?<span style="color:#a31515 xml <span style="color:red version<span style="color:blue =<span style="color:black "<span style="color:blue 1.0<span style="color:black " <span style="color:red encoding<span style="color:blue =<span style="color:black "<span style="color:blue utf-8<span style="color:black " <span style="color:blue ?>
<span style="color:blue <<span style="color:#a31515 GameReminders<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Reminder<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 PostponeDatetime<span style="color:blue ><span style="color:blue </<span style="color:#a31515 PostponeDatetime<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Games<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Games<span style="color:blue >
<span style="color:blue <<span style="color:#a31515 Dismessed<span style="color:blue ><span style="color:blue </<span style="color:#a31515 Dismessed<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 Reminder<span style="color:blue >
<span style="color:blue </<span style="color:#a31515 GameReminders<span style="color:blue >
[/code]
<br/>The code I use to deserialize the xml file looks like this (nothing new...):<br/><br/>
<div style="background-color:white;color:black
<pre>XmlSerializer serializer = <span style="color:blue new XmlSerializer(<span style="color:blue typeof(GameReminders));
TextReader textReader = <span style="color:blue new StreamReader(<span style="color:blue new MemoryStream(Encoding.UTF8.GetBytes(xmlString)));
GameReminders settings = (GameReminders)serializer.Deserialize(textReader);
textReader.Close();
textReader.Dispose();
[/code]
<br/>Now most probably if you the reader of this post is going to try it, it will work, but it does not work here and Im stuck because I cant continue if this does work!<br/><br/>Thanks!
View the full article