예제 #1
0
파일: XmlHelper.cs 프로젝트: aslyr/myVOlvue
        /// <summary>
        /// 修改节点的内容
        /// </summary>
        /// <param name="index">节点索引</param>
        /// <param name="xmlParameter">XML参数对象</param>
        public static void UpdateNode(int index, XmlParameter xmlParameter)
        {
            XmlDocument xDoc = GetXmlDom();
            XmlNodeList nlst = xDoc.DocumentElement.ChildNodes;

            if (nlst.Count <= index)
            {
                return;
            }
            if (nlst[index].Name == xmlParameter.Name)
            {
                UpdateNode(nlst[index], xmlParameter);
            }
            else
            {
                foreach (XmlNode xn in nlst[index])
                {
                    XmlNode xnd = GetNode(xn, xmlParameter.Name);
                    if (xnd != null)
                    {
                        UpdateNode(xnd, xmlParameter);
                    }
                }
            }
            xDoc.Save(_xPath);
        }
예제 #2
0
파일: XmlHelper.cs 프로젝트: aslyr/myVOlvue
 private static void UpdateNode(XmlNode node, XmlParameter xmlParameter)
 {
     node.InnerText = xmlParameter.InnerText;
     for (int i = 0; i < xmlParameter.Attributes.Length; i++)
     {
         for (int j = 0; j < node.Attributes.Count; j++)
         {
             if (node.Attributes[j].Name == xmlParameter.Attributes[i].Name)
             {
                 node.Attributes[j].Value = xmlParameter.Attributes[i].Value;
             }
         }
     }
 }
예제 #3
0
파일: XmlHelper.cs 프로젝트: aslyr/myVOlvue
        /// <summary>
        /// 修改属性值
        /// </summary>
        /// <param name="xmlParameter">XML参数</param>
        /// <param name="attributeValue">新属性值</param>
        public static void SetAttribute(XmlParameter xmlParameter, string attributeName, string attributeValue)
        {
            XmlDocument xDoc = GetXmlDom();
            XmlNodeList nlst = xDoc.DocumentElement.ChildNodes;

            foreach (XmlNode xns in nlst)              // 遍历所有子节点
            {
                if (xns.Name == xmlParameter.Name && xns.InnerText == xmlParameter.InnerText)
                {
                    ((XmlElement)xns).SetAttribute(attributeName, attributeValue);
                    break;
                }
                XmlNode tmp = GetNode(xns, xmlParameter);
                if (tmp != null)
                {
                    ((XmlElement)tmp).SetAttribute(attributeName, attributeValue);
                    break;
                }
            }
            xDoc.Save(_xPath);
        }
예제 #4
0
파일: XmlHelper.cs 프로젝트: aslyr/myVOlvue
        /// <summary>
        /// 修改节点的内容
        /// </summary>
        /// <param name="xmlParameter">XmlParameter对象</param>
        /// <param name="innerText">修改后的内容</param>
        /// <param name="attributeParameters">需要修改的属性</param>
        public static void UpdateNode(XmlParameter xmlParameter, string innerText, params AttributeParameter[] attributeParameters)
        {
            XmlDocument xDoc = GetXmlDom();
            XmlNodeList nlst = xDoc.DocumentElement.ChildNodes;

            foreach (XmlNode xns in nlst)              // 遍历所有子节点
            {
                if (xns.Name == xmlParameter.Name && xns.InnerText == xmlParameter.InnerText)
                {
                    UpdateNode(xns, innerText, attributeParameters);
                    break;
                }
                XmlNode tmp = GetNode(xns, xmlParameter);
                if (tmp != null)
                {
                    UpdateNode(tmp, innerText, attributeParameters);
                    break;
                }
            }
            xDoc.Save(_xPath);
        }
예제 #5
0
파일: XmlHelper.cs 프로젝트: aslyr/myVOlvue
 /// <summary>
 /// 获取指定节点名称的节点对象
 /// </summary>
 /// <param name="node">节点对象</param>
 /// <param name="xmlParameter">XML参数</param>
 public static XmlNode GetNode(XmlNode node, XmlParameter xmlParameter)
 {
     return(GetNode(node, xmlParameter.Name, node.InnerText));
 }