在没有标签的RichTextBox中显示XML文件

时间:2015-12-27 00:22:53

标签: c# xml

我想将我的XML文件显示为富文本框中的段落 没有任何标签

private void button1_Click(object sender, EventArgs e)
    {
        XmlTextReader reader = new XmlTextReader("practical1.xml");
       // XmlNodeType type;



        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element: // The node is an element.
                    this.richTextBox1.SelectionColor = Color.Blue;
                    this.richTextBox1.AppendText("<");
                    this.richTextBox1.SelectionColor = Color.Brown;
                    this.richTextBox1.AppendText(reader.Name);
                    this.richTextBox1.SelectionColor = Color.Blue;
                    this.richTextBox1.AppendText(">");
                    break;
                case XmlNodeType.Text: //Display the text in each element.
                    this.richTextBox1.SelectionColor = Color.Black;
                    this.richTextBox1.AppendText(reader.Value);
                    break;
                case XmlNodeType.EndElement: //Display the end of the element.
                    this.richTextBox1.SelectionColor = Color.Blue;
                    this.richTextBox1.AppendText("</");
                    this.richTextBox1.SelectionColor = Color.Brown;
                    this.richTextBox1.AppendText(reader.Name);
                    this.richTextBox1.SelectionColor = Color.Blue;
                    this.richTextBox1.AppendText(">");
                    this.richTextBox1.AppendText("\n");
                    break;

0 个答案:

没有答案