C# DataTable 序列化
/// <summary> /// 序列化 DataTable 成 XML /// </summary> /// <param name="dt"></param> /// <returns></returns> private static string SerializeDataTableToXml(DataTable dt) { StringBuilder strBuilder = new StringBuilder(); XmlWriter writer = XmlWriter.Create(strBuilder); XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); serializer.Serialize(writer, dt); writer.Close(); return strBuilder.ToString(); }
/// <summary> /// 序列化 XML 成 DataTable /// </summary> /// <param name="xml"></param> /// <returns></returns> private static DataTable SerializeXmlToDataTable(string xml) { StringReader strReader = new StringReader(xml); XmlReader xmlReader = XmlReader.Create(strReader); XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); DataTable dt = serializer.Deserialize(xmlReader) as DataTable; return dt; }
DMWebSvrSoapClient dmwss = new DMWebSvrSoapClient(); DateTime date = DateTime.Now; string dataStr1 = dmwss.GetVehicleInfo_Month(date.ToString("yyyy-MM-dd")); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(dataStr1); XmlNodeList xnList = xmldoc.SelectNodes("//DocumentElement/list"); foreach (XmlNode xn in xnList) { ListViewItem item = new ListViewItem(xn["time"].InnerText); item.SubItems.Add(xn["in_vehicle_count"].InnerText); item.SubItems.Add(xn["out_vehicle_count"].InnerText); listView.Items.Add(item); }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
上一篇: C# 获取指定范围的n个随机数
下一篇: 彻底找到 Tomcat 启动速度慢的元凶
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论