I have to embend webbrowser control into my application, so that I can show pieces of Xml code more nicely.I found two ways of doing this.The first and easiest was just to save the xml code in temporary xml file and navigate the webbrowser to it :
// save xml file and load it in XmlWebBrowser
XmlTextWriter wr = new XmlTextWriter("temp.xml",Encoding.UTF8);
node.WriteTo(wr);
wr.Close();
this.XmlwebBrowser.Navigate(Application.StartupPath + "\\temp.xml");
The second way was to show the code without saving it in temporary file.Doing it this way the xml code appears in webbrowser without being formated ( raw code).So before showing it I have to combine it with stylesheet similar to the default Internet Explorer stylesheet and after converting it into html format using XslCompiledTransform I was able to show it:
/// Trasform Xml to Html
XslCompiledTransform objTransform = new XslCompiledTransform();
StringWriter objStream = new StringWriter();
// load xml default style sheet
objTransform.Load("xmlprint.xsl");
objTransform.Transform(node,null,objStream);
string html = objStream.ToString();
// load html page
this.XmlwebBrowser.DocumentText = html;
Some usefull links:
Related posts:

One Comment
thanks a lot, buddy.
you saved my lot of time.