Expando Object for Xml

0

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.

    
asked by anonymous 24.04.2015 / 14:30

1 answer

1

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:

link

    
24.04.2015 / 16:48