XElement represents an XML element. This post will describe about how to convert Dictionary to XML Format.
Assume you want the XML to be in the following format,
The Dictionary is having <String, String> Format with Two Entries inside as shown below.
Now we have a List of dictionary as shown below,
Include the following Namespaces
using System.Xml.Linq;
Use the below method to convert the List<Dictionary> to XML (XElement)
if (MyList != null)
{
foreach (Dictionary<string, string> entry in MyList)
{
myXml.Add(new XElement(“param”,
new XElement(“key”, entry[“key”]),
new XElement(“value”, entry[“value”])
));
}
}
}