XDocument::Load Method (XmlReader^, LoadOptions)
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Setting PreserveWhitespace is not valid when loading from a XmlReader. The XmlReader will be configured to either read whitespace or not. The LINQ to XML tree will be populated with the whitespace nodes that the reader surfaces. This will be the behavior regardless of whether PreserveWhitespace is set or not.
There is a performance penalty if you set the SetLineInfo flag.
The line information is accurate immediately after loading the XML document. If you modify the XML tree after loading the document, the line information may become meaningless.
LINQ to XML's loading functionality is built upon XmlReader. Therefore, you might catch any exceptions that are thrown by the XmlReader::Create overload methods and the XmlReader methods that read and parse the document.
The following example loads the line information that it loads from the XmlReader. It then prints the line information.
This example produces the following output:
Element Name Line Position ------------ ---- -------- Root 1 2 Child 2 6 GrandChild 3 10
Available since 8
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1