Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XmlReader and Read Failure
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00851225
Message ID:
00852856
Views:
14
Hi Rick,

The XMLReader requires a valid XML file, not just a snippet. That is why you are getting the error.

>I need a reality check <g>...
>
>I have the following XML fragment:
>
>
><event sitename="West Wind Demo Link">
>	<url>http://rasnotebook/wconnect/testpage.wwd?Test2</url>
>	<time>11/17/2003 7:32:39 pm</time>
>	<message>Site is back up now.</message>
></event>
><event sitename="West Wind WebStore">
>	<url>http://rasnotebook/wconnect/testpage.wwd?Test3</url>
>	<time>11/17/2003 7:32:43 pm</time>
>	<message>Site is down.</message>
></event>
>
>
>I'm having problems parsing this code with an XML Reader. The code I have (below) runs through the first event and then stops with an exception after the white space. xr.Read() just fails.
>
>The code reads the tag and the white space after it, but on the next read - failuer with 'Unkown Error'...
>
>Any body have any idea what would cause the Read() to just fail? The document on disk is in fact just an XML fragment not a complete XML doc, which is why I'm using the XmlReaderin the first place (and the file could be very large).
>
>
>... data table stuff above
>XmlTextReader xr = new XmlTextReader(FileName);
>DataRow dr = null;
>
>while (xr.Read())
>{
>	if (xr.NodeType == XmlNodeType.Element)
>	{
>		if (xr.Name == "event")
>		{
>			if (xr.HasAttributes)
>			{
>				xr.MoveToAttribute(0);
>				dr = dt.NewRow();
>				dr["SiteName"] = xr.Value;
>			}
>		}
>		else if (xr.Name == "url")
>			dr["Url"] = xr.Value;
>		else if (xr.Name == "time")
>			try
>			{
>				dr["Time"] = XmlConvert.ToDateTime(xr.Value);
>			}
>			catch
>			{
>				dr["Time"] = Convert.ToDateTime("01/02/1900");
>			}
>		else if (xr.Name == "message")
>			dr["Message"] = xr.Value;
>	}
>	if (xr.NodeType == XmlNodeType.EndElement && xr.Name == "event")
>		dt.Rows.Add(dr);
>}
>
>xr.Close();
>
>return dt;
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform