I have a string
that contains a xml
. I want to set the value of the WebBrowser control with it and display as a xml
.
I can set the value with browser.DocumentText
, but how do I tell it to display as a XML ?
To give some code to the first solution @PaoloFalabella suggested (i.e. write string contents to a temporary xml file and navigate to it):
//create a random temporary file with an .xml file extension
var path = Path.GetTempPath();
var fileName = Guid.NewGuid().ToString() + ".xml";
var fullFileName = Path.Combine(path, fileName);
//write the contents of your xml string to the temporary file we just created
File.WriteAllText(fullFileName, xmlText); //xmlText is your xml string
//"navigate" to the file
webBrowser.Navigate(fullFileName); //webBrowser is your WebBrowser control
There is a good link here: Displaying XML in the .NET WebBrowser Control
public XmlDocument DocumentXml
{
set
{
Stream s = <defaultss.xsl from embedded resource file>
XmlReader xr = XmlReader.Create(s);
XslCompiledTransform xct = new XslCompiledTransform();
xct.Load(xr);
StringBuilder sb = new StringBuilder();
XmlWriter xw = XmlWriter.Create(sb);
xct.Transform(value, xw);
this.DocumentText = sb.ToString();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With