/// <summary> /// 保存路径配置(要求路径保存在顶层结点的下一层结点的path属性中) /// </summary> /// <param name="xmlDoc"></param> /// <param name="attrParams">包括属性名、属性值、XML保存路径的参数对象</param> public static void SetPath(this XmlDocument xmlDoc, XmlSaveAttrParams attrParams) { var pathNode = xmlDoc.ChildNodes[0].SelectSingleNode(attrParams.AttributeName); pathNode.Attributes["path"].Value = attrParams.Value; xmlDoc.Save(attrParams.XmlSavePath); }
/// <summary> /// 获取指定XML结点的指定属性值 /// </summary> /// <param name="xmlDoc"></param> /// <param name="attrParams">属性名称</param> /// <param name="childNodes"></param> public static void SetAttributeValue(this XmlDocument xmlDoc, XmlSaveAttrParams attrParams, params string[] childNodes) { var node = xmlDoc.SelectSingleNode(childNodes[0]); for (int i = 1; i < childNodes.Length; i++) { node = node.SelectSingleNode(childNodes[i]); } node.Attributes[attrParams.AttributeName].Value = attrParams.Value; xmlDoc.Save(attrParams.XmlSavePath); }