Create XStreamingElement from LINQ statement on XElement in CSharp

Description

The following code shows how to create XStreamingElement from LINQ statement on XElement.

Example


//from   w w w.  j a  v a 2 s . co m
using System;
using System.Linq;
using System.Xml.Linq;


public class MainClass{
   public static void Main(){
        XElement src = new XElement("Root",
                           new XElement("Child1", 1),
                           new XElement("Child2", 2),
                           new XElement("Child3", 3)
                       );
        XStreamingElement xse = new XStreamingElement("NewRoot",
                                    from el in src.Elements()
                                    where (int)el >= 2
                                    select el
                                );
        Console.WriteLine(xse);
    }
}




















Home »
  C# Tutorial »
    XML »




Load Parse
Document
Element
Attribute
Namespace
Query
Save
Schema
Style