Display XML held in a string

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I have a string with XML in it. I want to display this xml in a windows
form.

I have looked at Microsoft Web Browser control, but it seems to want to work
with a url. How can I just pass my xml string for displaying?

Thanks
Martin
 
You can always roll your own solution, just use something like the
IndentedTextWriter to write the various elements of the XML into a
neatly formatted stream and then display the string from the stream in a
RichTextBox, btw you can also write the XML string to a temp file and
then pass the location of that file as a URL to the webbrowser control.

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
I have run into the same problem. The workaround I am using is to place the
XML in a file. The other methods listed below are things I tried that didn't
work.

// File IO overhead
string tempUrl = @"C:\temp\docs\temp.xml";
FileInfo tempFile = new FileInfo(tempUrl);
if (tempFile.Exists)
{
tempFile.Delete();
}
StreamWriter writer = new StreamWriter(tempFile.OpenWrite());
writer.Write(splitDocument.DocumentXmlString);
writer.Close();
this.webBrowser1.Url = tempUrl;

//Won't format
//MemoryStream temp = new MemoryStream();
//StreamWriter writer = new StreamWriter(temp);
//writer.Write(splitDocument.DocumentXmlString);
//writer.Flush();
//temp.Position = 0;
//this.webBrowser1.DocumentStream = temp;

// Won't format
//Encoder utf8encoder = Encoding.UTF8.GetEncoder();
//char[] charArray = splitDocument.DocumentXmlString.ToCharArray();
//byte[] byteArray = new byte[utf8encoder.GetByteCount(charArray, 0,
byteArray.Length, true)];
//int charsUsed;
//int bytesUsed;
//bool completed;
//utf8encoder.Convert(charArray, 0, charArray.Length, byteArray, 0,
byteArray.Length, true,
// out charsUsed, out bytesUsed, out completed);
//this.webBrowser1.DocumentStream = new MemoryStream(byteArray);
 
Back
Top