All pastes #971099 Raw Edit

Stuff

public text v1 · immutable
·published 2008-04-04 14:41 UTC
rendered paste body
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace readXml
{
    public partial class Form1 : Form
    {
        XmlReader reader;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            textBox2.Text = openFileDialog1.FileName;

            reader = new XmlTextReader(textBox2.Text);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element: // The node is an element.
                            textBox1.Text +="<" + reader.Name;

                        while (reader.MoveToNextAttribute()) // Read the attributes.
                            textBox1.Text += " " + reader.Name + "='" + reader.Value + "'";
                            textBox1.Text += ">";
                        break;
                    case XmlNodeType.Text: //Display the text in each element.
                            textBox1.Text += reader.Value;
                        break;
                    case XmlNodeType.EndElement: //Display the end of the element.
                            textBox1.Text += "</" + reader.Name;
                            textBox1.Text += ">";
                            textBox1.Text += "\r\n";
                        break;
                }
            }
        }
    }
}