Sample C#
public static String XmlNodeToString(XmlNode node, int indentation = 2) { using (var sw = new StringWriter()) { using (var xw = new XmlTextWriter(sw)) { xw.Formatting = Formatting.Indented; xw.Indentation = indentation; node.WriteContentTo(xw); } return sw.ToString(); } }
Sample VB.NET
Public Shared Function XmlNodeToString(node As XmlNode, Optional indentation As Integer = 2) As String Using sw = New StringWriter() Using xw = New XmlTextWriter(sw) xw.Formatting = Formatting.Indented xw.Indentation = indentation node.WriteContentTo(xw) End Using Return sw.ToString() End Using End Function
for more informations on indentation = 2 see XmlTextWriter.Indentation Property
RT @CodeSnippetsNET: How to get XmlNode as #Xml String with indentation in C# and #VB .NET http://t.co/p48L8QV9VN #dotnet #csharp #visualba…
RT @CodeSnippetsNET: How to get XmlNode as #Xml String with indentation in C# and #VB .NET http://t.co/p48L8QV9VN #dotnet #csharp #visualba…
RT @CodeSnippetsNET: How to get XmlNode as #Xml String with indentation in C# and #VB .NET http://t.co/p48L8QV9VN #dotnet #csharp #visualba…
RT @CodeSnippetsNET: How to get XmlNode as #Xml String with indentation in C# and #VB .NET http://t.co/p48L8QV9VN #dotnet #csharp #visualba…
RT @CodeSnippetsNET: How to get XmlNode as #Xml String with indentation in C# and #VB .NET http://t.co/p48L8QV9VN #dotnet #csharp #visualba…