Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
XmlReader and Read Failure
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
XmlReader and Read Failure
Divers
Thread ID:
00851225
Message ID:
00851225
Vues:
47
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;
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform