Click here to Skip to main content
14,934,046 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a xml with large data.I know almost 90% of my xml content but remaining 10 % I need to serialize and deserialize dynamically.I know the Type of that part.
Sample xml
<Vehicle version="2.0">
<Engine Name="Turbo"/>
<Engine Name="Kappa"/>

<Car Name="XX" Engine ="Turbo" Type="Premium">

<Car Name="YY" Engine ="Kappa">


Here the values inside the tag <value> will be be dynamic and I don't the content initially ,but I know the Type of that object.
Please anyone help to solve this issue.

What I have tried:

I have the data classes for that 90% of that xml.
Updated 11-Apr-17 20:02pm

1 solution

Have you considered using a Dictionary for storing these values? Here is how you can build it from XML.

This code will take all the values tags and store all its descendants as a dictionary.

string xml = @"<start>

XDocument xDocument = XDocument.Parse(xml);
Dictionary<string,string> dynamicThings = xDocument.Root.Elements()
                                           .Where(x=> x.Name == "values")
                                           .Select(x => new { Key = x.Name, Value = x.Value })
                                           .ToDictionary(x => x.Key.ToString(), x => x.Value);
sathish kumbanad 12-Apr-17 2:11am
Thanks lw@zi for your quick reply.I will try it and let you know whether it is solve my issue or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900