Mega Code Archive

 
Categories / C# / XML LINQ
 

XDocument Load(String, LoadOptions) loads an XDocument from a file with option

using System; using System.Linq; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass{    public static void Main(){       XDocument doc1 = XDocument.Load("PurchaseOrder.xml", LoadOptions.None);       Console.WriteLine("nodes if not preserving whitespace: {0}", doc1.DescendantNodes().Count());       XDocument doc2 = XDocument.Load("PurchaseOrder.xml", LoadOptions.PreserveWhitespace);       Console.WriteLine("nodes if preserving whitespace: {0}", doc2.DescendantNodes().Count());    } }