C # XElement: Node Formatting with HTML

I am extracting XML node from XElement. When I use XElement.Value, it removes any HTML that may be in node.

I know that if I do XElement.ToString () I can save the HTML, but it also gives me node tags. Is there a way to extract the content of a node as is without removing the HTML?

Greetings.

+2


a source to share


2 answers


You need to concatenate the nodes inside the XElement, for example:

node.Nodes().Aggregate(new StringBuilder(), (sb, n) => sb.Append(n.ToString())).ToString()

      



Or, in .Net 4.0:

String.Concat(node.Nodes())

      

+1


a source


As an alternative:



using System.Xml.XPath;

string xml = node.CreateNavigator().InnerXml;

      

+2


a source







All Articles