日期:2014-05-20  浏览次数:20723 次

如何把XML文档显示在text文本框中?
如题。
找了找,好像应该用XmlTextWriter,但是XmlTextWriter只能输出到Console.out或者文件中。

------解决方案--------------------
带格式的显示到文本框中可以用如下的方法:
XmlDocument doc = new XmlDocument();
doc.Load( "xmlfile.xml ");
StringWriter writer1 = new StringWriter();
XmlTextWriter writer2 = new XmlTextWriter(writer1);
writer2.Formatting = Formatting.Indented;
writer2.Indentation=1;
writer2.IndentChar= '\t ';
doc.WriteTo(writer2);
this.textBox1.Text = writer1.ToString();