Create XElement with namespace in CSharp
Description
The following code shows how to create XElement with namespace.
Example
using System;//from w w w . j a va2 s .c om
using System.Linq;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass{
public static void Main(){
XNamespace aw = "http://www.domain.com";
XElement xmlTree1 = new XElement(aw + "Root",
new XElement(aw + "Child1", 1),
new XElement(aw + "Child5", 5),
new XElement(aw + "Child6", 6)
);
XElement xmlTree2 = new XElement(aw + "Root",
from el in xmlTree1.Elements()
where((int)el >= 3 && (int)el <= 5)
select el
);
Console.WriteLine(xmlTree2);
}
}