suppose I have the following XML:
<appSettings>
<add key="key1" value="value1" />
<add key="key2" value="value2" />
<add key="key3" value="value3" />
<add key="key4" value="value4" />
</appSettings>
and I would like to transform it to an object like:
AppSettings["key1"] = "value1";
AppSettings["key2"] = "value2";
AppSettings["key3"] = "value3";
and so forth …
I've looked it up on the internet and haven't found yet something useful. Can someone help me out on this ?
Easy.
var xd = XDocument.Parse(xml);
var AppSettings = xd.Root.Elements("add")
.ToDictionary(
xe => xe.Attribute("key").Value,
xe => xe.Attribute("value").Value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With