Select from XML - CSharp LINQ

CSharp examples for LINQ:Select

Description

Select from XML

Demo Code


using System;/*  w ww.j a va  2  s  . co  m*/
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Data;

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

            Console.WriteLine("\nUsing an xml source");
            // create the source
            XElement xmltree = createXML();
            // perform the query
            IEnumerable<XElement> xmlEnum = from e in xmltree.Elements() select e;
            // write out the elements
            foreach (string str in xmlEnum)
            {
                Console.WriteLine("Element {0}", str);
            }
            
            
    }
    
        static XElement createXML()
        {
            return new XElement("fruit",
                new XElement("name", "Oracle"),
                new XElement("name", "MySQL"),
                new XElement("name", "C"),
                new XElement("name", "fig"),
                new XElement("name", "XML"),
                new XElement("name", "file"),
                new XElement("name", "PLSQL")
            );
        }
    }

Result


Related Tutorials