/// <summary> /// 修改节点的内容 /// </summary> /// <param name="fileFullName">文件名称,包括完整路径</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); }
/// <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; } }
/// <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); }
/// <summary> /// 修改属性值 /// </summary> /// <param name="fileFullName">文件名称,包括完整路径</param> /// <param name="xpara">XML参数</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); }
/// <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; } }
/// <summary> /// 修改属性值 /// </summary> /// <param name="xDoc">XmlDocument对象</param> /// <param name="xpara">XML参数</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); }
/// <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); }
/// <summary> /// 修改节点的内容 /// </summary> /// <param name="xDoc">XMLDocument对象</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); }
/// <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)); }
/// <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)); }