📄 readxml.cs
字号:
//Copyright (C) 2006 dooogo.com
//Author:benben
//www.aspxclub.com
using System;
using System.Xml;
namespace Club.Framework.Xml
{
/// <summary>
/// ReadPlace 的摘要说明。
/// </summary>
public class ReadXML
{
public ReadXML()
{
}
public static string ReadListType(string xmlPath,string _value)
{
string reText=string.Empty;
if(_value==string.Empty)
{
return reText;
}
xmlPath=Globals.GetFilePath(xmlPath);
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(xmlPath);
XmlNodeList items = xmlDoc.DocumentElement.ChildNodes;
for(int i=0;i<items.Count;i++)
{
if(items[i].Attributes!=null)
{
if(items[i].Attributes.Count>0)
{
if(items[i].Attributes[0].Value==_value)
{
reText = items[i].InnerText;
break;
}
}
}
}
return reText;
}
public static string[] ReadPlace(string xmlPath,int country,int province,int city)
{
xmlPath=Globals.GetFilePath(xmlPath);
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(xmlPath);
string[] places=new string[3];
XmlNodeList countryNodes = xmlDoc.DocumentElement.ChildNodes;
XmlNode countryNode=null;
if(country==0)
{
return places;
}
for(int i=0;i<countryNodes.Count;i++)
{
if(countryNodes[i].Attributes[0].Value==country.ToString())
{
places[0] = (countryNodes[i].InnerXml.Split('<')[0].Trim());
countryNode=countryNodes[i];
break;
}
}
if(countryNode!=null)
{
if(province==0)
{
return places;
}
XmlNodeList provinceNodes=countryNode.ChildNodes;
XmlNode provinceNode=null;
for(int i=0;i<provinceNodes.Count;i++)
{
if(provinceNodes[i].Attributes!=null)
{
if(provinceNodes[i].Attributes[0].Value==province.ToString())
{
places[1] = provinceNodes[i].InnerXml.Split('<')[0].Trim();
provinceNode=provinceNodes[i];
break;
}
}
}
if(provinceNode!=null)
{
if(city==0)
{
return places;
}
XmlNodeList cityNodes=provinceNode.ChildNodes;
for(int i=0;i<cityNodes.Count;i++)
{
if(cityNodes[i].Attributes!=null)
{
if(cityNodes[i].Attributes[0].Value==city.ToString())
{
places[2] = cityNodes[i].InnerXml.Split('<')[0].Trim();
break;
}
}
}
}
}
return places;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -