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 = XElement.Parse(" ",
LoadOptions.None);
int whiteSpaceNodes = xmlTree1
.DescendantNodesAndSelf()
.OfType()
.Where(tNode => tNode.ToString().Trim().Length == 0)
.Count();
Console.WriteLine("Count of white space nodes (not preserving whitespace): {0}",
whiteSpaceNodes);
XElement xmlTree2 = XElement.Parse(" ",
LoadOptions.PreserveWhitespace);
whiteSpaceNodes = xmlTree2
.DescendantNodesAndSelf()
.OfType()
.Where(tNode => tNode.ToString().Trim().Length == 0)
.Count();
Console.WriteLine("Count of white space nodes (preserving whitespace): {0}",
whiteSpaceNodes);
}
}