XElement.Parse Method (String, LoadOptions) Loads an XElement from a string that contains XML : XML Load « XML LINQ « VB.Net






XElement.Parse Method (String, LoadOptions) Loads an XElement from a string that contains XML

  

Imports System
Imports System.Xml
Imports System.Xml.XPath

Public Class MainClass

    Public Shared Sub Main()
        Dim whiteSpaceNodes As Integer
        
        Dim xmlTree1 As XElement = XElement.Parse("<Root> <Child> </Child> </Root>", LoadOptions.None)
        whiteSpaceNodes = xmlTree1 _
            .DescendantNodesAndSelf() _
            .OfType(Of XText)() _
            .Where(Function(ByVal tNode As XNode) tNode.ToString().Trim().Length = 0) _
            .Count()
        Console.WriteLine("Count of white space nodes (not preserving whitespace): {0}", whiteSpaceNodes)
        
        Dim xmlTree2 As XElement = XElement.Parse("<Root> <Child> </Child> </Root>", LoadOptions.PreserveWhitespace)
        whiteSpaceNodes = xmlTree2 _
            .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.using XElement.Parse to load Xml from String
2.XElement.Parse (String) Loads an XElement from a string that contains XML.
3.XElement.Parse(String, LoadOptions.SetLineInfo)
4.Load the Employees.xml and store the contents into an XElement object.
5.XElement.Load (String) loads an XElement from a file.
6.XElement.Load (String, LoadOptions) loads an XElement from a file
7.XElement.Load("Order.xml", LoadOptions.SetBaseUri Or LoadOptions.SetLineInfo)
8.XElement.Load (TextReader) loads an XElement from a TextReader.
9.XElement.Load(TextReader, LoadOptions) loads an XElement from a TextReader
10.XElement.Load(TextReader, LoadOptions.SetLineInfo)