S
sjoshi
I'm trying to read a simple xml file that I created but the XmlReader
keeps choking with this message
There is an error in XML document (0, 0).
----> System.Xml.XmlException : Root element is missing.
The code to read is
private static T ReadFromXml<T>(Stream s) where T: new()
{
T rVal = default(T);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Auto;
using (XmlReader reader = XmlReader.Create(s, settings))
{
XmlSerializer serializer = new
XmlSerializer(typeof(T));
rVal = (T)serializer.Deserialize(s);
}
return rVal;
}
The xml files looks like this...
<?xml version="1.0" encoding="utf-8"?>
<Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>123</id>
<title>The way of prana and qi</title>
<author>Sunit Joshi</author>
<genre>Metaphysical</genre>
<price>21.99</price>
<publish_date>11/21/2007 4:19 PM</publish_date>
<description>An in-depth look at life energy</description>
</Book>
Any ideas what is happening here...
thanks
Sunit
keeps choking with this message
There is an error in XML document (0, 0).
----> System.Xml.XmlException : Root element is missing.
The code to read is
private static T ReadFromXml<T>(Stream s) where T: new()
{
T rVal = default(T);
XmlReaderSettings settings = new XmlReaderSettings();
settings.ConformanceLevel = ConformanceLevel.Auto;
using (XmlReader reader = XmlReader.Create(s, settings))
{
XmlSerializer serializer = new
XmlSerializer(typeof(T));
rVal = (T)serializer.Deserialize(s);
}
return rVal;
}
The xml files looks like this...
<?xml version="1.0" encoding="utf-8"?>
<Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<id>123</id>
<title>The way of prana and qi</title>
<author>Sunit Joshi</author>
<genre>Metaphysical</genre>
<price>21.99</price>
<publish_date>11/21/2007 4:19 PM</publish_date>
<description>An in-depth look at life energy</description>
</Book>
Any ideas what is happening here...
thanks
Sunit