load XML via a textreader using LINQ using XmlTextReader - CSharp XML

CSharp examples for XML:XML LINQ

Description

load XML via a textreader using LINQ using XmlTextReader

Demo Code


using System;//from  w w  w. j  a va 2  s. c  o m
using System.IO;
using System.Xml;
using System.Xml.Linq;

class MainClass
    {
        static void Main(string[] args)
        {

            string filename = @"ProductCatalog.xml";

            // load via an xmlreader
            Console.WriteLine("Loading using an XmlReader");
            XmlReader xmlreader = new XmlTextReader(new StreamReader(filename));
            XElement root = XElement.Load(xmlreader);
            // write out the xml
            Console.WriteLine(root);


        }
    }

Result


Related Tutorials