How can I display XML with WebBrowser control?

https://stackoverflow.com/questions/5157545/how-can-i-display-xml-with-webbrowser-control

为WebBrowser控件增加显示XML文档接口(c#)

Show XML in WebBrowser control 

https://learn.microsoft.com/en-us/answers/questions/1181957/show-xml-in-webbrowser-control

View XML Files Easily with XmlGridViewControl

https://www.codeproject.com/articles/16497/view-xml-files-easily-with-xmlgridviewcontrol

声明xml字符串:

string xml = "....";

声明xslt 转换类:

XslCompiledTransform xslt = new XslCompiledTransform();

调用xslt sheet文件:

xslt.Load("XSLTFile1.xslt");

将字符串转成流类型

TextReader tr = new StringReader(xml);

声明XPathDocument 类

XPathDocument xpath = new XPathDocument(tr);

定义写字符串的流类型

TextWriter tw = new StringWriter();

定义xml输出流:

XmlWriter xwriter = XmlWriter.Create(tw);

将xml 转成 html 字符串

xslt.Transform(xpath, xwriter);

WebBrowser输出html:

webBrowser1.DocumentText = tw.ToString();

posted on 2023-08-23 09:01  一切从新开始  阅读(34)  评论(0编辑  收藏  举报