遍历XML文件

前端之家收集整理的这篇文章主要介绍了遍历XML文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

///读取并遍历XML文件并绑定到下拉框


public void bind_ddshi()

{
L_shi.Items.Clear();
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(Server.MapPath(".") + "/XMLConfig/region_name.xml");
}
catch
{
return;
}
XmlNodeList nodeList = xmlDoc.SelectNodes("datalist/region");
if (nodeList != null && nodeList.Count > 0)
{

foreach (XmlNode node in nodeList)
{
ListItem listtemp = new ListItem(node.Attributes["region_name"].Value,node.Attributes["region_name"].Value);
L_shi.Items.Add(listtemp);
}
}

}



XML文件如下:

<datalist> <region region_name="全部"> </region> <region region_name="哈尔滨"> </region> <region region_name="齐齐哈尔"></region> <region region_name="牡丹江"></region> <region region_name="佳木斯"></region> <region region_name="大庆"> </region> <region region_name="绥化"></region> <region region_name="鸡西"></region> <region region_name="鹤岗"></region> <region region_name="双鸭山"> </region> <region region_name="伊春"></region> <region region_name="七台河"></region> <region region_name="黑河"></region> <region region_name="大兴安岭"> </region> </datalist>

猜你在找的XML相关文章