旗下导航:搜·么
当前位置:网站首页 > XML教程 > 正文

从xml中猎取都市,省份称号【XML教程】,xml,城市,省份名称

作者:搜教程发布时间:2019-12-01分类:XML教程浏览:91评论:0


导读:近来没事,写了个在项目常常要取都市或省份名的要领,所以改成了一个类.轻易今后挪用//********************************************...
近来没事,写了个在项目常常要取都市或省份名的要领,所以改成了一个类.轻易今后挪用

//********************************************************************************
//*                                                                              *
//    功用形貌:从xml中猎取数据
//    版本编号:owendu V1.1
//    初始建立: 2006.08.27
//    末了修正: 2006.10.08
//*                                                                              *
//********************************************************************************

//依据cityid,猎取返回cityname   ---------------xmlurl 指的是全部站点的路征
//页面挪用体式格局以下:<script language=javascript>GetCityName("<%=cityid%>","<%=System.Configuration.ConfigurationSettings.AppSettings["LocalSiteURL"]%>")</script>
function GetCityName(cityid,xmlurl)
{
     
     var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0");
       XmlDoc_city.async=false;
       XmlDoc_city.validateOnParse=false;
       var Url=xmlurl+"XmlData/city.xml";
       XmlDoc_city.load(Url);
    
  //
    if (XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "")
  {
  
   var city;
   var cities = XmlDoc_city.documentElement.selectNodes("city");
   
   for (var i=0; i < cities.length; i++)
   {
    city = cities[i];
    if (city.getAttribute("cityid") == cityid)
    {
    
     document.write(city.getAttribute("cityname"));
     break;
    } 
     //obj2.options[obj2.length] = new Option(city.getAttribute("cityname"),city.getAttribute("cityid"));
   }
     }
    // else
    // {
        //alert('您的浏览器不支持xml文件读取,因而本页面制止您的操纵,引荐运用IE5.0以上能够处理此题目!');
    // }
}
//依据省份id,猎取返回省名   ---------------xmlurl 指的是全部站点的路征 
function GetPRoviceName(pid,xmlurl)
{
     
    var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0");
    XmlDoc_city.async=false;
    XmlDoc_city.validateOnParse=false;
    var Url=xmlurl+"XmlData/province.xml";
    XmlDoc_city.load(Url);    
    if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "")
 { 
  var city;
  var cities = XmlDoc_city.documentElement.selectNodes("province");
  
  for (var i=0; i < cities.length; i++)
  {
   city = cities[i];
   if (city.getAttribute("provinceid") == pid)
   {   
    document.write(city.getAttribute("provincename"));
    break;
   }     
  }
 } 
}
//依据区域districtid,猎取返回区域名   ---------------xmlurl 指的是全部站点的路征 
function GetProviceName(districtid,xmlurl)
{
     
    var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0");
    XmlDoc_city.async=false;
    XmlDoc_city.validateOnParse=false;
    var Url=xmlurl+"XmlData/district.xml";
    XmlDoc_city.load(Url);    
    if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "")
 { 
  var city;
  var cities = XmlDoc_city.documentElement.selectNodes("district");
  
  for (var i=0; i < cities.length; i++)
  {
   city = cities[i];
   if (city.getAttribute("districtid") == pid)
   {   
    document.write(city.getAttribute("districtname"));
    break;
   }     
  }
 } 
}
//依据省份id,都市id,区域(县)id,猎取返回省都市名区域名   ---------------xmlurl 指的是全部站点的路征 
function GetName(pid,cityid,districtid ,xmlurl)
{
   var cityname="";
   var provicename="";
   var districtname="";
    //
    
    var XmlDoc_p = new ActiveXObject("MSXML2.DOMDocument.3.0");
    XmlDoc_p.async=false;
    XmlDoc_p.validateOnParse=false;
    var UrlProvice=xmlurl+"XmlData/province.xml";
    XmlDoc_p.load(UrlProvice);    
    //
     
    var XmlDoc_city = new ActiveXObject("MSXML2.DOMDocument.3.0");
    XmlDoc_city.async=false;
    XmlDoc_city.validateOnParse=false;
    var Urlcity=xmlurl+"XmlData/city.xml";
    XmlDoc_city.load(Urlcity);   
    
    //
    var XmlDoc_district = new ActiveXObject("MSXML2.DOMDocument.3.0");
    XmlDoc_district.async=false;
    XmlDoc_district.validateOnParse=false;
    var Urldis=xmlurl+"XmlData/district.xml";
    XmlDoc_district.load(Urldis);   
    // 
    if(XmlDoc_p.readyState == 4 && XmlDoc_p.xml != "")
 { 
  var provice;
  var provices = XmlDoc_city.documentElement.selectNodes("province");
  
  for (var i=0; i < provices.length; i++)
  {
   provice = provices[i];
   if (provice.getAttribute("provinceid") == pid)
   {   
      provicename=provice.getAttribute("provincename");
    break;
   }     
  }
 }
 
  if(XmlDoc_city.readyState == 4 && XmlDoc_city.xml != "")
 { 
  var city;
  var citys = XmlDoc_city.documentElement.selectNodes("city");
  
  for (var i=0; i < citys.length; i++)
  {
   city = citys[i];
   if (city.getAttribute("cityid") == cityid)
   {   
      cityname=city.getAttribute("cityname");
    break;
   }     
  }
 }
 
  if(XmlDoc_district.readyState == 4 && XmlDoc_district.xml != "")
 { 
  var district;
  var districts = XmlDoc_district.documentElement.selectNodes("district");
  
  for (var i=0; i < districts.length; i++)
  {
   district = districts[i];
   if (district.getAttribute("districtid") == districtid)
   {   
      districtname=district.getAttribute("districtname");
    break;
   }     
  }
 }
 var name=provicename+" "+cityname+" "+ districtname;
 document.write(name);
  
}

以上就是从xml中猎取都市,省份称号的内容,更多相关内容请关注ki4网(www.ki4.cn)!

标签:xml城市省份名称


欢迎 发表评论: