Exemple #1
0
        /// <summary>
        /// 修改节点的内容
        /// </summary>
        /// <param name="fileFullName">文件名称,包括完整路径</param>
        /// <param name="Index">节点索引</param>
        /// <param name="para">XML参数对象</param>
        public static void UpdateNode(string fileFullName, int Index, XmlParameter para)
        {
            XmlDocument xDoc = xmlDoc(fileFullName);

            UpdateNode(xDoc, Index, para);
            xDoc.Save(fileFullName);
        }
Exemple #2
0
        /// <summary>
        /// 创建一个XML文档
        /// </summary>
        /// <param name="fileFullName">文件名称,包括完整路径</param>
        /// <param name="rootp">根结点对象</param>
        /// <param name="elemName">元素节点名称</param>
        /// <param name="paras">XML参数</param>
        public static void CreateXMLFile(string fileFullName, XmlParameter rootp, string elemName, params XmlParameter[] paras)
        {
            XmlDocument xDoc = new XmlDocument();
            XmlNode     xn;

            xn = xDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            xDoc.AppendChild(xn);
            XmlNode root = xDoc.CreateElement(rootp.Name);
            string  ns   = rootp.NamespaceOfPrefix == null ? "" : root.GetNamespaceOfPrefix(rootp.NamespaceOfPrefix);

            foreach (AttributeParameter ap in rootp.Attributes)
            {
                XmlNode rootAtt = xDoc.CreateNode(XmlNodeType.Attribute, ap.Name, ns == "" ? null : ns);
                rootAtt.Value = ap.Value;
                root.Attributes.SetNamedItem(rootAtt);
            }
            xDoc.AppendChild(root);
            XmlNode ln = xDoc.CreateNode(XmlNodeType.Element, elemName, null);

            AppendChild(xDoc, ln, paras);
            root.AppendChild(ln);
            try
            {
                xDoc.Save(fileFullName);
            }
            catch
            {
                throw;
            }
        }
Exemple #3
0
        /// <summary>
        /// 修改属性值
        /// </summary>
        /// <param name="fileFullName">文件名称,包括完整路径</param>
        /// <param name="xpara">XML参数</param>
        /// <param name="attps">属性参数</param>
        public static void SetAttribute(string fileFullName, XmlParameter xpara, params AttributeParameter[] attps)
        {
            XmlDocument xDoc = xmlDoc(fileFullName);

            SetAttribute(xDoc, xpara, attps);
            xDoc.Save(fileFullName);
        }
Exemple #4
0
        /// <summary>
        /// 修改属性值
        /// </summary>
        /// <param name="fileFullName">文件名称,包括完整路径</param>
        /// <param name="xpara">XML参数</param>
        /// <param name="attributeName">属性名称</param>
        /// <param name="newValue">新属性值</param>
        public static void SetAttribute(string fileFullName, XmlParameter xpara, string attributeName, string newValue)
        {
            XmlDocument xDoc = xmlDoc(fileFullName);

            SetAttribute(xDoc, xpara, attributeName, newValue);
            xDoc.Save(fileFullName);
        }
Exemple #5
0
 /// <summary>
 /// 修改节点的内容
 /// </summary>
 /// <param name="node">修改的节点对象</param>
 /// <param name="para">XML参数对象</param>
 public static void UpdateNode(XmlNode node, XmlParameter para)
 {
     node.InnerText = para.InnerText;
     for (int i = 0; i < para.Attributes.Length; i++)
     {
         node.Attributes.Item(i).Value = para.Attributes[i].Value;
     }
 }
Exemple #6
0
        /// <summary>
        /// 修改属性值
        /// </summary>
        /// <param name="xDoc">XmlDocument对象</param>
        /// <param name="xpara">XML参数</param>
        /// <param name="attributeName">属性名称</param>
        /// <param name="newValue">新属性值</param>
        public static void SetAttribute(XmlDocument xDoc, XmlParameter xpara, string attributeName, string newValue)
        {
            XmlElement xe = (XmlElement)GetNode(xDoc, xpara);

            if (xe == null)
            {
                return;
            }
            SetAttribute(xe, attributeName, newValue);
        }
Exemple #7
0
        /// <summary>
        /// 修改属性值
        /// </summary>
        /// <param name="xDoc">XmlDocument对象</param>
        /// <param name="xpara">XML参数</param>
        /// <param name="attps">属性参数</param>
        public static void SetAttribute(XmlDocument xDoc, XmlParameter xpara, params AttributeParameter[] attps)
        {
            XmlElement xe = (XmlElement)GetNode(xDoc, xpara);

            if (xe == null)
            {
                return;
            }
            SetAttribute(xe, attps);
        }
Exemple #8
0
        /// <summary>
        /// 修改节点的内容
        /// </summary>
        /// <param name="xDoc">XMLDocument对象</param>
        /// <param name="Index">节点索引</param>
        /// <param name="para">XML参数对象</param>
        public static void UpdateNode(XmlDocument xDoc, int Index, XmlParameter para)
        {
            XmlNode node = GetNode(xDoc, Index, para.Name);

            UpdateNode(node, para);
        }
Exemple #9
0
 /// <summary>
 /// 获取指定节点名称的节点对象
 /// </summary>
 /// <param name="node">节点对象</param>
 /// <param name="xpar">XML参数</param>
 public static XmlNode GetNode(XmlNode node, XmlParameter xpar)
 {
     return(GetNode(node, xpar.Name, node.InnerText));
 }
Exemple #10
0
 /// <summary>
 /// 获取指定节点名称的节点对象
 /// </summary>
 /// <param name="xDoc">XmlDocument对象</param>
 /// <param name="xpar">XML参数</param>
 public static XmlNode GetNode(XmlDocument xDoc, XmlParameter xpar)
 {
     return(GetNode(xDoc, xpar.Name, xpar.InnerText));
 }