T
Tony Johansson
Hi!
I have this Xml file below and this small console program. At the end I have
class Movie. I want to serialize these three Movie object into a generic
collection of List<Movie>. When I run this program I get run time Exception
saying
"InvalidOperationException was unhandled There is an error in
XML-document(0,0)".
The xml document is well formed so it shouldn'y be any problem with it.
So can anybody tell me why the runtime complains about the XML file ?
static void Main(string[] args)
{
List<Movie> list = new List<Movie>();
FileStream fs = new FileStream("XMLFile2.xml", FileMode.Open);
XmlSerializer xs = new XmlSerializer(typeof(List<Movie>));
list = (List<Movie>)xs.Deserialize(fs);
}
<?xml version="1.0" encoding="utf-8" ?>
<movies date="2009-11-18">
<movie>
<title>My Sister's Keeper</title>
<runningLength>109</runningLength>
<productionYear>2009</productionYear>
<isbnNumber>9100120820</isbnNumber>
<url>http://images.filmtipset.se/posters/86432038.jpg</url>
</movie>
<movie>
<title>Fight Club</title>
<runningLength>139</runningLength>
<productionYear>1999</productionYear>
<isbnNumber>9100123064</isbnNumber>
<url>http://images.filmtipset.se/posters/93394736.jpg</url>
</movie>
<movie>
<title>Star Trek</title>
<runningLength>127</runningLength>
<productionYear>2009</productionYear>
<isbnNumber>9172321385</isbnNumber>
<url>http://images.filmtipset.se/posters/83532544.jpg</url>
</movie>
</movies>
using System;
using System.Xml.Serialization;
public class Movie
{
private string title = string.Empty;
private string url = string.Empty;
private string runningLength;
private string productionYear;
private string isbnNumber;
public string Title
{
get { return title; }
set { title = value; }
}
public string RunningLength
{
get { return runningLength; }
set { runningLength = value; }
}
public string ProductionYear
{
get { return productionYear; }
set { productionYear = value; }
}
public string IsbnNumber
{
get { return isbnNumber; }
set { isbnNumber = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
//Tony
I have this Xml file below and this small console program. At the end I have
class Movie. I want to serialize these three Movie object into a generic
collection of List<Movie>. When I run this program I get run time Exception
saying
"InvalidOperationException was unhandled There is an error in
XML-document(0,0)".
The xml document is well formed so it shouldn'y be any problem with it.
So can anybody tell me why the runtime complains about the XML file ?
static void Main(string[] args)
{
List<Movie> list = new List<Movie>();
FileStream fs = new FileStream("XMLFile2.xml", FileMode.Open);
XmlSerializer xs = new XmlSerializer(typeof(List<Movie>));
list = (List<Movie>)xs.Deserialize(fs);
}
<?xml version="1.0" encoding="utf-8" ?>
<movies date="2009-11-18">
<movie>
<title>My Sister's Keeper</title>
<runningLength>109</runningLength>
<productionYear>2009</productionYear>
<isbnNumber>9100120820</isbnNumber>
<url>http://images.filmtipset.se/posters/86432038.jpg</url>
</movie>
<movie>
<title>Fight Club</title>
<runningLength>139</runningLength>
<productionYear>1999</productionYear>
<isbnNumber>9100123064</isbnNumber>
<url>http://images.filmtipset.se/posters/93394736.jpg</url>
</movie>
<movie>
<title>Star Trek</title>
<runningLength>127</runningLength>
<productionYear>2009</productionYear>
<isbnNumber>9172321385</isbnNumber>
<url>http://images.filmtipset.se/posters/83532544.jpg</url>
</movie>
</movies>
using System;
using System.Xml.Serialization;
public class Movie
{
private string title = string.Empty;
private string url = string.Empty;
private string runningLength;
private string productionYear;
private string isbnNumber;
public string Title
{
get { return title; }
set { title = value; }
}
public string RunningLength
{
get { return runningLength; }
set { runningLength = value; }
}
public string ProductionYear
{
get { return productionYear; }
set { productionYear = value; }
}
public string IsbnNumber
{
get { return isbnNumber; }
set { isbnNumber = value; }
}
public string Url
{
get { return url; }
set { url = value; }
}
}
//Tony