LoadOptions.PreserveWhitespace
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
Public Class MainClass
Public Shared Sub Main()
Dim sr As TextReader
Dim whiteSpaceNodes As Integer
sr = New StringReader("<Root> <Child> </Child> </Root>")
Dim xmlTree2 As XDocument = XDocument.Load(sr, LoadOptions.PreserveWhitespace)
sr.Close()
whiteSpaceNodes = xmlTree2 _
.Element("Root") _
.DescendantNodesAndSelf() _
.OfType(Of XText)() _
.Where(Function(ByVal tNode As XNode) tNode. _
ToString().Trim().Length = 0).Count()
Console.WriteLine("Count of white space nodes (preserving whitespace): {0}", whiteSpaceNodes)
End Sub
End Class
Related examples in the same category