In article <11*********************@g44g2000cwa.googlegroups. com>,
<st****@gmail.com> wrote:
: I have a string which contains an xml document in my app.
:
: Does anyone know of an easy way to display XML data in a browser, with
: nice indentations between nodes, and maybe even the +/- controls that
: IE uses when displaying XML?
Let IE do the work for you. Below is a simplified version of the code
at
http://xrl.us/gq7i ("Hosting an ActiveX Control on a Windows Form").
Write your XML string to a temporary file, and then point IE at it.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using AxSHDocVw;
namespace BrowserView
{
public class MainForm : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;
private AxWebBrowser browser;
public MainForm()
{
InitializeComponent();
string path = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolde r.Personal),
"foo.xml");
DisplayFile(path);
}
private void DisplayFile(string path)
{
browser = new AxWebBrowser();
browser.BeginInit();
browser.Dock = DockStyle.Fill;
Controls.Add(browser);
browser.EndInit();
browser.TitleChange += new DWebBrowserEvents2_TitleChangeEventHandler(browser _TitleChange);
Cursor currentCursor = Cursor.Current;
try
{
Cursor.Current = Cursors.WaitCursor;
Uri uri = new Uri("file://" + path);
object arg1 = 0; object arg2 = ""; object arg3 = ""; object arg4 = "";
browser.Navigate(uri.ToString(), ref arg1,ref arg2,ref arg3,ref arg4);
}
catch (Exception e)
{
MessageBox.Show(e.Message + "\n" + e.StackTrace, "Navigation failure");
}
finally
{
Cursor.Current = currentCursor;
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(840, 525);
this.Name = "MainForm";
this.Text = "MainForm";
}
#endregion
private void browser_TitleChange(object sender, DWebBrowserEvents2_TitleChangeEvent e)
{
Text = e.text;
}
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
}
}
Enjoy,
Greg