I've been fine recently, and I wrote a method that often requires the name of a city or province in projects, so I changed it to a class. Convenient to call later
//************************************************ *********************************
//* *
// Function description: Get data from xml
// Version number: owendu V1.1
//Initial creation: 2006.08.27
// Last modified: 2006.10.08
//* *
//************************************************ *********************************
//According to cityid, get and return cityname ---------------xmlurl refers to the roadmap of the entire site
//The page calling method is as follows: <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('Your browser does not support reading xml files, so your operation is prohibited on this page. It is recommended to use IE5.0 or above to solve this problem!');
// }
}
//According to the province id, get the returned province name ---------------xmlurl refers to the roadmap of the entire site
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;
}
}
}
}
//According to the district districtid, get the returned district name ---------------xmlurl refers to the roadmap of the entire site
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;
}
}
}
}
//According to the province id, city id, region (county) id, get the returned province, city name and region name ------------------xmlurl refers to the roadmap of the entire site
function GetName(pid,cityid,districtid,xmlurl)
{
var cityname="";
var provisionname="";
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 provision;
var provices = XmlDoc_city.documentElement.selectNodes("province");
for (var i=0; i < provisions.length; i++)
{
provice = provices[i];
if (provice.getAttribute("provinceid") == pid)
{
provisionname=provice.getAttribute("provincename");
break;
}
}
}
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)
{
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);
}
http://www.cnblogs.com/owendu/archive/2006/10/16/530580.html