LoadOptions.PreserveWhitespace : XML File Read « XML « VB.Net






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

1.Use XML Reader to display XML tag, Node type and attributesUse XML Reader to display XML tag, Node type and attributes
2.Load Xml document and print attributes
3.XmlTextReader: XmlNodeType Element, Text and EndElement XmlTextReader: XmlNodeType Element, Text and EndElement
4.Using XmlReaderSettings and XmlWriterSettings
5.Reading an XML file example
6.Is starting element
7.Loads the XML document from the specified TextReader.
8.Loads the XML document from the specified string.