using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Xml; namespace ParsingXmlC { public partial class Form1 : Form { XmlTextReader BooksReader; public Form1() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); // Create the XMLTextReader object that reads from the file BooksReader = new XmlTextReader(@Application.StartupPath + "\\books.xml"); } private void listBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click_1(object sender, EventArgs e) { // Read the nodes until the end of file is reached while (BooksReader.Read()) { switch (BooksReader.NodeType) { case XmlNodeType.Element: listBox1.Items.Add("Element: " + BooksReader.Name); break; case XmlNodeType.Text: listBox1.Items.Add("Text: " + BooksReader.Value); break; } } BooksReader.Close(); } } }