Пример #1
0
        /// <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
 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
        /// <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
        /// <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
        /// <summary>
        /// 修改屬性值
        /// </summary>
        /// <param name="xmlParameter">XML參數</param>
        /// <param name="attributeParameters">屬性參數</param>
        public static void SetAttribute(XmlParameter xmlParameter, 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)
                {
                    SetAttribute((XmlElement)xns, attributeParameters);
                    break;
                }
                XmlNode tmp = GetNode(xns, xmlParameter);
                if (tmp != null)
                {
                    SetAttribute((XmlElement)tmp, attributeParameters);
                    break;
                }
            }
            xDoc.Save(_xPath);
        }
Пример #6
0
 /// <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));
 }