To remove all children from XMLNode in C# and VB.NET you can use the follwing snippet.
Sample C#
public static XmlDocument RemoveAllChildren(XmlNode xmlNode) { if (xmlNode.IsNull() || String.IsNullOrEmpty(xmlNode.ToString())) { return null; } while (xmlNode.HasChildNodes) { xmlNode.RemoveChild(xmlNode.FirstChild); } return xmlNode.OuterXml.ToXmlDocument(); }
Sample VB.NET
Public Shared Function RemoveAllChildren(xmlNode As XmlNode) As XmlDocument If xmlNode.IsNull() OrElse [String].IsNullOrEmpty(xmlNode.ToString()) Then Return Nothing End If While xmlNode.HasChildNodes xmlNode.RemoveChild(xmlNode.FirstChild) End While Return xmlNode.OuterXml.ToXmlDocument() End Function
RT @CodeSnippetsNET: How to remove all children from XMLNode .NET http://t.co/DLXJ1HfKoz #csharp #vb #dotnet
RT @CodeSnippetsNET: How to remove all children from XMLNode .NET http://t.co/DLXJ1HfKoz #csharp #vb #dotnet