xml document

  • Thread starter Thread starter stotty
  • Start date Start date
S

stotty

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?

Matt
 
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?

IE uses a stylesheet that generates the html for a given XML document, if
memory serves, which may not be what you want. Have you tried simply using
the IE browser and having it host it?
 
You need an xsl file to render HTML from XML. Internet Explorer provides one
built-in, but it you want another your XML file has to include a reference
to it:

<?xml version="1.0" encoding="Windows-1252" ?>
<?xml-stylesheet type="text/xsl" href="file:///C:\myXsl.xsl" ?>


--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
: 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.SpecialFolder.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
 
Back
Top