求XML读取方法,该怎么处理
求XML读取方法
本人准备做一个火车票查询网站
数据用的是偷偷网的接口
接口返回的是XML格式
XML地址是:http://www.twototwo.net/api/train.aspx?action=QueryByTrainNumber&key=963134e2-0091-40b3-8b2a-6d0d4f9ece4e&trainNumber=G7255&ignoreStartDate=0&like=1
这个怎么用c#读取出来
显示的效果类似:
http://www.twototwo.net/train/checi/1016866692.html
------解决方案--------------------
XML,一般使用CMarkup类,上网看下怎么使用吧
------解决方案--------------------
tiny xml
------解决方案--------------------
本人准备做一个火车票查询网站
数据用的是偷偷网的接口
接口返回的是XML格式
XML地址是:http://www.twototwo.net/api/train.aspx?action=QueryByTrainNumber&key=963134e2-0091-40b3-8b2a-6d0d4f9ece4e&trainNumber=G7255&ignoreStartDate=0&like=1
这个怎么用c#读取出来
显示的效果类似:
http://www.twototwo.net/train/checi/1016866692.html
------解决方案--------------------
XML,一般使用CMarkup类,上网看下怎么使用吧
------解决方案--------------------
tiny xml
------解决方案--------------------
- C# code
#region 获取查询结果 private string GetQueryResult() { XmlDataDocument xmlDoc = new XmlDataDocument(); StringBuilder sb = new StringBuilder(); string apiUrl = string.Empty; apiUrl = "http://www.twototwo.net/api/train.aspx?action=QueryByTrainNumber&key=963134e2-0091-40b3-8b2a-6d0d4f9ece4e&trainNumber=G7255&ignoreStartDate=0&like=1"; xmlDoc.Load(apiUrl); if (xmlDoc.SelectSingleNode("result/error") != null) { sb.Append("<tr><td colspan=\"17\">没有查询到直达列车</td></tr>"); } else { XmlNodeList items = xmlDoc.SelectSingleNode("result/main").ChildNodes; //遍历每一行 foreach (XmlNode node in items) { if (node.Name.ToString().Equals("item")) { string CheCiBianHao = node.SelectSingleNode("checibianhao").InnerText; string CheCiMingCheng = node.SelectSingleNode("checimingcheng").InnerText; //数据都取到了,接下来的自己处理了 } } } return sb.ToString(); } #endregion