Mega Code Archive

 
Categories / C# / XML LINQ
 

XDocument Parse(String, LoadOptions) parse a string to create a new XDocument with option

using System; using System.IO; using System.Linq; using System.Xml.Linq; using System.Xml; using System.Collections; using System.Collections.Generic; public class MainClass {     public static void Main()     {         string str = @"<?xml version=""1.0""?>             <Root>                 <Child>Content</Child>             </Root>";         XDocument doc1 = XDocument.Parse(str, LoadOptions.PreserveWhitespace);         Console.WriteLine("nodes when preserving whitespace: {0}", doc1.DescendantNodes().Count());         XDocument doc2 = XDocument.Parse(str, LoadOptions.None);         Console.WriteLine("nodes when not preserving whitespace: {0}", doc2.DescendantNodes().Count());     } }