0
I am using Expands Object (c# VS 2013) to read a complex xml file. I now need to read this Expands Object and turn it back into an xml.
0
I am using Expands Object (c# VS 2013) to read a complex xml file. I now need to read this Expands Object and turn it back into an xml.
1
I’ve already done it:
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:
Thanks a lot for the help! I will test your solution tonight. But generally Voce believes that an Expandoobject containing an XML like this one can be reassembled by your solution? <? xml version="1.0" encoding="utf-8" ? > <People> <person Id="1"> <Name>Waseem</Name> <Age>25</Age> </person> <person Id="2"> <Name> <Age>35</Age> <Children> <person Id="7"> <name>Pedrim</#Xa; <<Age>15</Age> </person> </Children> </person> </People>
Basically he has us "children". In the problem that inspired you there is the presence of us children, "grandchildren" kk. Etc...
with some adjustments is possible. But the idea is this.
Could I get the ajuses please!? I have a class that gives me a list where every xml tag is an object! How could I bring this to xml again!?
Thiago Custodio thank you so much for your help! I adapted my class to provide for your one Expandoobject It worked great Thank you!
Browser other questions tagged c# xml objects
You are not signed in. Login or sign up in order to post.
What have you done? Do you have any code available? It could reduce a little the scope of the question to what problem you are having in reading and transformation?
– Felipe Avelar
Felipe good afternoon sorry for the delay in answering. I am using this code:( http://blog.waseem-sabjee.com/2014/09/14/how-to-convert-xml-document-to-a-dynamic-object-in-net/) It transforms an xml into a list of Expandoobjects (which is very good because I need to read xml files which I don’t know the structure). But I can’t transform this Dynamic Expandoobjects List into XML again. This is a very difficult face if you can please help me! Thanks in advance!
– Luiz Rocha