C#技巧之缩进输出XML文档到TextBox

今天在写一个工具时候突然用到了Xml,并且要输出到TextBox中,于是就写了一下啊,上网一看还挺多人问这问题,于是晒一下@_@!
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            XmlTextWriter writer = new XmlTextWriter(sw);
            writer.Formatting = Formatting.Indented;
            writer.Indentation = 4;
            writer.IndentChar = ' ';
            doc.WriteContentTo(writer);

            editResult.Text = sb.ToString();

相关的文章在这里

posted @ 2007-12-24 12:23  moonz-wu  阅读(1764)  评论(4编辑  收藏  举报