日期:2014-05-18 浏览次数:21270 次
/// <summary> /// 获取指定节点的值 /// </summary> /// <param name="strFileName">文件路径</param> /// <param name="nodeName">节点名称</param> /// <param name="value">设置后的值</param> /// <param name="nodeDir">指定节点所在的节点目录</param> /// <returns></returns> public static string GetNodeValue(string strFileName, string nodeName, string nodeDir) { string value = null; try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); XmlNodeList nodeList = xmlDoc.SelectSingleNode(nodeDir).ChildNodes;//获取bookstore节点的所有子节点 foreach (XmlNode xn in nodeList) //遍历所有子节点 { XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型 if (xe.Name == nodeName) { value = xe.InnerText.Trim(); break; } } } catch (Exception exp) { throw exp; } return value; } /// <summary> /// 获取指定节点下面对应属性的值 /// </summary> /// <param name="strFileName">文件路径</param> /// <param name="nodeName">节点名称</param> /// <param name="nodeDir">指定节点所在的节点目录</param> /// <param name="attribute">节点对应的属性名称</param> /// <returns></returns> public static string GetNodeValue(string strFileName, string nodeName, string nodeDir, string attribute) { string value = null; try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strFileName); XmlNodeList nodeList = xmlDoc.SelectSingleNode(nodeDir).ChildNodes;//获取bookstore节点的所有子节点 foreach (XmlNode xn in nodeList) //遍历所有子节点 { XmlElement xe = (XmlElement)xn; //将子节点类型转换为XmlElement类型 if (xe.Name == nodeName) { //value = xe.InnerText.Trim(); value = (xe).Attributes[attribute].Value; break; } } } catch (Exception exp) { throw exp; } return value; }
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e) { string serverpath