解析带前缀的xml

geo_xml

<?xml version="1.0" encoding="utf-8"?>
<q1:HotelGeoList xmlns:q1="http://api.elong.com/staticInfo/">
  <q1:HotelGeo>
    <q1:id>1</q1:id>
    <q1:country>中国</q1:country>
    <q1:provinceName>北京                </q1:provinceName>
    <q1:provinceId>0100</q1:provinceId>
    <q1:cityName>北京</q1:cityName>
    <q1:cityCode>0101</q1:cityCode>
    <q1:properties>2098</q1:properties>
    <q1:url>http://www.elong.com/hotels/Search.aspx?raCityName=%u5317%u4EAC</q1:url>


/// <summary>
        /// 根据城市名称获取城市ID
        /// </summary>
        /// <param name="cityName"></param>
        /// <returns></returns>
        private string GetCityIdByName(string cityName)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(HttpContext.Current.Server.MapPath("/xmlhotelfile/geo_cn.xml"));

            XmlElement root = doc.DocumentElement;

            XmlNodeList list1 = root.GetElementsByTagName("q1:HotelGeo");
            int len = list1.Count;
            for (int i = 0; i < len; i++)
            {
                string cityId = list1[i]["q1:cityCode"].InnerText;

                if (list1[i]["q1:cityName"].InnerText == cityName)
                {
                    i = len;
                    return cityId;
                    break;
                }
            }
            return "";
        }




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值