我有一个包含 xml
的 string
。我想用它设置 WebBrowser 控件的值并显示为 xml
。
我可以使用 browser.DocumentText
设置值,但是如何让它显示为 XML?
最佳答案
为@PaoloFalabella 建议的第一个解决方案提供一些代码(即将字符串内容写入临时 xml 文件并导航到它):
//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
关于c# - 如何使用 WebBrowser 控件显示 XML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5157545/