Retrieve full string of XElement with mixed content
.net-3.5, c#, linq-to-xml, xml
Solution
Solution for .NET 4
var result = String.Join("", rootElement.Nodes()).Trim();
Complete code (for .NET 3.5):
XElement rootElement = XElement.Parse("<root>Hello<child>Wold</child></root>");
var nodes = rootElement.Nodes().Select(n => n.ToString()).ToArray();
string result = String.Join("", nodes).Trim();
Console.WriteLine(result);
// writes "Hello<child>World</child>"
Fast solution without joining all nodes:
XElement rootElement = XElement.Parse("<root>Hello<child>Wold</child></root>");
var reader = rootElement.CreateReader();
reader.MoveToContent();
string result = reader.ReadInnerXml();
Problem
Let's say I have the following content in an `XElement` object ``` <root>Hello<child>Wold</child></root> ``` If I use `XElement.ToString()`, this gives me ``` "<root xmnls="someschemauri">Hello<child>World</child></root>" ``` If I use XElement.Value, I will get ``` "Hello World" ``` I need to get ``` "Hello <child>World</child>" ``` What is the proper function to do this(if there is one)?