Create XElement from LINQ statement and filter element value in CSharp

Description

The following code shows how to create XElement from LINQ statement and filter element value.

Example


//from   ww w  .  j a v  a  2  s .  c  om
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;


public class MainClass{
   public static void Main(){
        XElement xmlTree1 = new XElement("Root",
            new XElement("Child1", 1),
            new XElement("Child6", 6)
        );
        
        XElement xmlTree2 = new XElement("Root",
            from el in xmlTree1.Elements()
            where((int)el >= 3 && (int)el <= 5)
            select el
        );
        Console.WriteLine(xmlTree2);
        
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style