C# 构建XML的简单示例:
1 var pars = new Dictionary<string, string> 2 { 3 {"url","https://www.baidu.com/"}, 4 {"name","jack"}, 5 {"sex","0"}, 6 }; 7 StringWriter sw = new StringWriter(); 8 XmlTextWriter xtw = new XmlTextWriter(sw); 9 xtw.WriteStartElement("xml"); 10 foreach (var par in pars) 11 { 12 xtw.WriteElementString(par.Key, par.Value); 13 } 14 xtw.WriteEndElement(); 15 Console.WriteLine(sw.ToString());