hs2d
hs2d

Reputation: 6199

C# Best way to hold xml data

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?

Upvotes: 0

Views: 5502

Answers (2)

LoveMeSomeCode
LoveMeSomeCode

Reputation: 3937

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));

Upvotes: 1

James Johnson
James Johnson

Reputation: 46047

If I'm understanding you correctly, you might consider loading the data into an XmlDocument or XDocument and storing it in cache with a CacheDependency:

XmlDocument xDoc = new XmlDocument(); 

if (Cache.Get("MenuData") == null) 
{ 
    xDoc.Load(Server.MapPath("/MenuData.xml")); 
    Cache.Insert("SiteNav", xDoc, new CacheDependency(Server.MapPath("/MenuData.xml"))); 
} 
else 
{ 
    xDoc = (XmlDocument)HttpContext.Current.Cache.Get("MenuData"); 
} 

Upvotes: 0

Related Questions