How can I convert a NameValueCollection like:
var mydata = new NameValueCollection();
mydata.Add("UserID", "3698521478963");
mydata.Add("Password", "23584");
mydata.Add("VerifyCode", "23654");
to a XML String like this :
XML Data:
How can I convert a NameValueCollection like:
var mydata = new NameValueCollection();
mydata.Add("UserID", "3698521478963");
mydata.Add("Password", "23584");
mydata.Add("VerifyCode", "23654");
to a XML String like this :
XML Data:
You can use LINQ-to-XML to achieve that, for example :
var mydata = new NameValueCollection();
mydata.Add("UserID", "3698521478963");
mydata.Add("Password", "23584");
mydata.Add("VerifyCode", "23654");
var result = new XElement("Root",
mydata.AllKeys.Select(o => new XElement(o, mydata[o]))
);
Console.WriteLine(result.ToString());
output :
<Root>
<UserID>3698521478963</UserID>
<Password>23584</Password>
<VerifyCode>23654</VerifyCode>
</Root>