How to read a String to Textreader using C# and VB.NET

To read a String to Textreader using C# and VB.NET you can use the snippet below.

Sample C#

using(TextReader textReader = new StringReader("string"))
{
    //...
}

Sample VB.NET

Using textReader As TextReader = New StringReader("string")
    '...
End Using

How to convert xml string to XmlNode in C# and VB.NET

To convert xml string to XmlNode in C# and VB.NET you can use the following snippet.

Sample C#

public static XmlNode XmlStringToXmlNode(string xmlInputString)
{
	if (String.IsNullOrEmpty(xmlInputString.Trim())) { throw new ArgumentNullException("xmlInputString"); }
	var xd = new XmlDocument();
	using (var sr = new StringReader(xmlInputString))
	{
		xd.Load(sr);
	}
	return xd;
}

Sample VB.NET

Public Shared Function XmlStringToXmlNode(xmlInputString As String) As XmlNode
	If String.IsNullOrEmpty(xmlInputString.Trim()) Then
		Throw New ArgumentNullException("xmlInputString")
	End If
	Dim xd = New XmlDocument()
	Using sr = New StringReader(xmlInputString)
		xd.Load(sr)
	End Using
	Return xd
End Function

How to convert xml string to XNode in C# and VB.NET

To convert xml string to XNode in C# and VB.NET you can use the snippet below.

Sample C#

public static XNode XmlStringToXNode(string xmlInputString)
{
	if (String.IsNullOrEmpty(xmlInputString.Trim())) { throw new ArgumentNullException("xmlInputString"); }
	using (var stringReader = new StringReader(xmlInputString))
	{
		using (var xmlReader = XmlReader.Create(stringReader))
		{
			xmlReader.Read();
			return XNode.ReadFrom(xmlReader);
		}
	}
}

Sample VB.NET

Public Shared Function XmlStringToXNode(xmlInputString As String) As XNode
	If String.IsNullOrEmpty(xmlInputString.Trim()) Then
		Throw New ArgumentNullException("xmlInputString")
	End If
	Using stringReader = New StringReader(xmlInputString)
		Using xmlReader__1 = XmlReader.Create(stringReader)
			xmlReader__1.Read()
			Return XNode.ReadFrom(xmlReader__1)
		End Using
	End Using
End Function