Using XmlReader with XElement


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main()
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreWhitespace = true;

        using (XmlReader r = XmlReader.Create("foo.xml", settings))
        {
            r.ReadStartElement("log");
            while (r.Name == "logentry")
            {
                XElement logEntry = (XElement)XNode.ReadFrom(r);
                int id = (int)logEntry.Attribute("id");
                DateTime date = (DateTime)logEntry.Element("date");
                string source = (string)logEntry.Element("source");

            }
            r.ReadEndElement();
        }

    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.