ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

GetNestedXml

This one allows you to get nested XML from within a node. Let's say you're parsing an HTML file using the XDocument class and you want to pull out the nested code including tags. This is what you can use!

Source

public static string GetNestedXml(this XElement xe)
{
    StringBuilder xml = new StringBuilder();

    foreach (XNode node in xe.Nodes())
    {
        xml.Append(node.ToString());
    }

    return xml.ToString();
}

Example

p.Text = x.Element("Czech").Element("Text").InnerXml();

Author: Jakub Kottnauer

Submitted on: 1 jun. 2010

Language: C#

Type: System.Xml.Linq.XElement

Views: 4569