I'm using Expando Object (C # VS 2013) to read a complex xml file. I need now to read this Expando Object and turn it back into an xml.
I'm using Expando Object (C # VS 2013) to read a complex xml file. I need now to read this Expando Object and turn it back into an xml.
I've already done this:
internal class ToXml
{
public string GetXml(ExpandoObject obj, XElement rootElement)
{
foreach (var keyValue in obj)
{
if (keyValue.Value is ExpandoObject)
{
var root = new XElement(keyValue.Key);
GetXml(keyValue.Value as ExpandoObject, root);
if (rootElement == null)
rootElement = root;
else
rootElement.Add(root);
}
if (keyValue.Value is string)
{
var xml = new XElement(keyValue.Key, keyValue.Value);
rootElement.Add(xml);
}
}
return rootElement.ToString();
}
}
Follow the Gist: