读取xml

XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("DemandFiled_DropDown.xml")); //加载Xml文件
XmlElement rootElem = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = rootElem.GetElementsByTagName("person"); //获取person子节点集合
foreach (XmlNode node in personNodes)
{
//string strName = ((XmlElement)node).GetAttribute("name"); //获取name属性值
//Console.WriteLine(strName);
XmlNodeList subAgeNodes = ((XmlElement)node).GetElementsByTagName("age"); //获取age子XmlElement集合
//if (subAgeNodes.Count == 1)
//{
// string strAge = subAgeNodes[0].InnerText;
// Console.WriteLine(strAge);
//}
foreach (XmlNode nodeage in subAgeNodes)
{
string strAgec = ((XmlElement)node).GetAttribute("code");
string strc = subAgeNodes[0].Value;
string strAge = subAgeNodes[0].InnerText;
ListItem li = new ListItem(strAge,strc);
ddlServerType.Items.Add(li);
}
}

posted @ 2014-07-03 10:39  JIN__JIN  阅读(143)  评论(0编辑  收藏  举报