Hi all,
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. For kicks I dumped the doc after
fixup with open and close tags into a DOM and there it works just fine...
XMLReader should be able to deal with a fragment though, so I'm kinda
stumped. Also checked the encoding of the file just to be sure...
The code reads the tag and the white space after it, but on the next read -
failuer with an XmlException...
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 XmlReader in the first place (well the file will
get very large too).
.... 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;
}
Any ideas?
+++ Rick ---
d Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
----------------------------------
Making waves on the Web