1 using System.Web;
2
3 public string GetLeaderInfo(string symbol)
4 {
5 //获取高管信息的路径
6 XElement ele = XElement.Load("path.xml");
7 string path = ele.Element("leader").Value;
8
9 //首次读取缓存
10 string jsoncache = HttpRuntime.Cache.Get(symbol) as string;
11 if (jsoncache == null || jsoncache.Equals(""))
12 {
13 //读取数据
14 XmlDocument doc = new XmlDocument();
15 doc.Load(path);
16
17 string strSearch = "root/高管信息[@代码='" + symbol + "']";
18
19 XmlNode searchNode = doc.SelectSingleNode(strSearch);
20 XmlElement element = (XmlElement)searchNode;
21 xmltoJson json = new xmltoJson();
22 jsoncache = json.XmlToJSON(element);
23 //加缓存
24 HttpRuntime.Cache.Insert(symbol, jsoncache, null, DateTime.UtcNow.AddMinutes(2), System.Web.Caching.Cache.NoSlidingExpiration);
25 }
26 return jsoncache;
27 }