using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Xml;
static class ParsingUsingXmlTextReader
{
public static void Main()
{
XmlTextReader m_xmlr = null;
//Create the XML Reader
m_xmlr = new XmlTextReader("C:\\Personal\\family.xml");
//Disable whitespace so that you don't have to read over whitespaces
m_xmlr.WhitespaceHandling = WhitespaceHandling.None;
//read the xml declaration and advance to family tag
m_xmlr.Read();
//read the family tag
m_xmlr.Read();
//Load the Loop
while (!m_xmlr.EOF) {
//Go to the name tag
m_xmlr.Read();
//if not start element exit while loop
if (!m_xmlr.IsStartElement()) {
break; // TODO: might not be correct. Was : Exit While
}
//Get the Gender Attribute Value
dynamic genderAttribute = m_xmlr.GetAttribute("gender");
//Read elements firstname and lastname
m_xmlr.Read();
//Get the firstName Element Value
dynamic firstNameValue = m_xmlr.ReadElementString("firstname");
//Get the lastName Element Value
dynamic lastNameValue = m_xmlr.ReadElementString("lastname");
//Write Result to the Console
Console.WriteLine("Gender: " + genderAttribute + " FirstName: " + firstNameValue + " LastName: " + lastNameValue);
Console.Write(Constants.vbCrLf);
}
//close the reader
m_xmlr.Close();
}
}