Is there a way to display an Xml file in a Windows form application; just like the IE browser does?
Printable View
Is there a way to display an Xml file in a Windows form application; just like the IE browser does?
Code:string s = File.ReadAllText("test.xml");
textbox1.text = s;
You can also put an IEBrowser control inside the form and load it via the control.
That way you'll be able to expand and collapse the nodes.
I would like the user to be able to expand and collapse the Xml nodes, so this sounds like a good solution.Quote:
Originally Posted by Arjay
But, how can I put an IEbrowser control inside the form?
Use the WebBrowser Control.
Goto : Add Reference, Under COM tab, choose WebBrowser. (System.Windows.Forms)
You will find this control in the toolbox after adding it.
Now just place it on the form.
MMH.
Thanks.
Now I have a WebBrowser object on my form.
I tried the following just to see if someting happens, but there was no result.
Is this the way to go?Code:StreamReader stream = new StreamReader(fileName);
this.webBrowser1.DocumentStream = stream.BaseStream;
My intention is to display the contents of a DataSet in an Xml format, before the data is actually saved to an Xml file.
string filename = "C:\\temp\example.xml";
webBrowser1.Url = new Uri(filename);
It works.Quote:
Originally Posted by dannystommen
As I understand, using the Url property requires a file. But, is there a way to display the contents of a DataSet in an Xml format on the WebBrowser before the data is actually saved to an Xml file.
It does not neccesarally need a file, you could also fill in an url, tryQuote:
Originally Posted by Holly_vi
webBrowser1.Url = new Uri("http://www.codeguru.com");
To get a dataset into Xml you should use the XmlDataDocument type instead of XmlDocument.
The next codesnippet with a normal XmlDocument works
I never worked with datasets but it should be something like the nextCode:XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Properties.config");
webBrowser1.Url = new Uri(xmlDoc.BaseURI);
Code:XmlDataDocument xmlDataDoc = new XmlDataDocument(yourDataSet);
webBrowser1.Url = new Uri(xmlDataDoc.BaseURI);
I need to display the contents of my DataSet before it is saved to file, so when I do as you suggest, xmlDataDoc.BaseURI returns null.Quote:
Originally Posted by dannystommen
Any suggestions?
I looked at it, and xmlDataDoc is indeed empty.
I suggest to save the xmlDataDoc in a temp directory, then open the file with a xmlDocument, and after you did everything you wanted to do, you could delete the file
Code:XmlDataDocument xmlDataDoc = new XmlDataDocument(dataset);
string fileName = @"C:\temp\data.xml";
xmlDataDoc.Save(fileName);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
webBrowser1.Url = new Uri(xmlDoc.BaseURI);
//do the things you want to do
//at the end, delete the file
FileInfo fi = new FileInfo(fileName);
fi.Delete();