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:
00854519
Views:
21
<g>

Yeah, that's close to what I ended up doing. Actually I was writing out a bunch of strings as text and I switched all that to use an XMLWriter which turned out to be more efficient anyway...

Still seems very strange to nothave an option to encode an XML string if you can encode everything else...

+++ Rick ---

>Rick,
>
>>Do you know how to Convert a string to a proper XML encoded string? XmlConvert works to convert everything EXCEPT a string... (entity conversions etc.)
>
>Try this:
>
>
>System.Text.StringBuilder sb = new System.Text.StringBuilder();
>System.Xml.XmlTextWriter tw = new System.Xml.XmlTextWriter(new
>	System.IO.StringWriter(sb));
>tw.WriteString("this is <a comment>");
>tw.Flush();
>Console.WriteLine(sb.ToString());
>Console.ReadLine();
>
>
>>>Hi Rick,
>>>
>>>The XMLReader requires a valid XML file, not just a snippet. That is why you are getting the error.
>>
>>Yeah, I figured that out a little later on. It ended up making this logging code a whole lot more complex having to write out an end tag and overwriting it each time.
>>
>>BTW, another question for the walking .Net Encyclopedia:
>>
>>Do you know how to Convert a string to a proper XML encoded string? XmlConvert works to convert everything EXCEPT a string... (entity conversions etc.)
>>
>>+++ Rick ---
>>
>>
>>>
>>>>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?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform