读书人

求XML读取步骤

发布时间: 2012-12-31 11:57:52 作者: rapoo

求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
[解决办法]


#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

读书人网 >VC/MFC

热点推荐