I have the following code for the method XmlToDictionary. But how to give input from a button, so that the XML data will be converted to Dictionary
XML Input
<messageTags>
<tag key="35" value="U1" />
<tag key="49" value="GEMI1" />
<tag key="8" value="FIX.4.1" />
<tag key="9" value="732" />
<messageTags/>
I want the output as below
35=U149=GEMI18=FIX.4.19=732
Code of XmlToDictionary()
public static Dictionary<string, string> XmlToDictionary(string key, string value, XElement baseElm)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
foreach (XElement elm in baseElm.Elements())
{
string dictKey = elm.Attribute(key).Value;
string dictVal = elm.Attribute(value).Value;
dict.Add(dictKey, dictVal);
}
return dict;
}
Code for button click()
private void button2_Click(object sender, EventArgs e)
{
XElement xs = new XElement("messageTags", "tag");
XmlToDictionary("23", "EUI", xs);
richTextBox4.Text = XmlToDictionary("messageTags","tag",xs).ToString();
}