Converting the children of XElement to string

Michael picture Michael · Jun 19, 2010 · Viewed 12.2k times · Source

Possible Duplicate:
Best way to get InnerXml of an XElement?

I am using an XElement to hold a block of HTML serverside.

I would like to convert the children of that XElement into a string, sort of like an "InnerHtml" property does in javascript.

Can someone help me on this please? :)

Answer

Quartermeister picture Quartermeister · Jun 19, 2010

The other answers will work if the element only contains other elements. If you want to include text as well, you'll want to use Nodes() instead of Elements():

var result = string.Concat(element.Nodes());