我想将我的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;