C#保存xml数据的最佳方法 [英] C# Best way to hold xml data

查看:50
本文介绍了C#保存xml数据的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Web服务请求数据并接收一个xml文件.不要泛滥该服务,最好的方法是缓存/存储xml,因此当应用程序再次启动时,它将使用该缓存的xml.接收到的xml中的数据将每24小时更改一次,因此从旧的请求应用程序经过的时间仍然必须创建新的数据.

保存这些数据的最佳解决方案是什么?

也许使用SQLite保留一些历史记录?

解决方案

您可以将其流式传输到文件中:

 ///保存:System.Xml.XmlDocument doc =新的System.Xml.XmlDocument();System.IO.File.WriteAllText(filename,doc.Value);///将其加载回:System.Xml.XmlDocument xdoc =新的System.Xml.XmlDocument();xdoc.LoadXml(System.IO.File.ReadAllText(filename)); 

Im requesting data from web service and receive a xml file.Not do flood the service good idea would be to cache/store the xml so when the application is started again it would use that cached xml. The data in received xml will change in every 24 hours so afther that time is passed from old request application must create new one anyway.

What would be the best solution to keep that data?

EDIT: Maybe use SQLite to keep some history?

解决方案

You can just stream it to a file:

/// saving it :
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.IO.File.WriteAllText(filename, doc.Value);

/// loading it back in :
System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument();
xdoc.LoadXml(System.IO.File.ReadAllText(filename));

这篇关于C#保存xml数据的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆