예제 #1
0
 /// <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);
 }
예제 #2
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;
     }
 }
예제 #3
0
 /// <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);
 }
예제 #4
0
 /// <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);
 }
예제 #5
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);
 }
예제 #6
0
 /// <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);
 }
예제 #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);
 }
예제 #8
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);
 }
예제 #9
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);
 }
예제 #10
0
 /// <summary>
 /// 创建一个XML文档
 /// </summary>
 /// <param name="fileFullName">文件名称,包括完整路径</param>
 /// <param name="rootp">根结点对象</param>
 /// <param name="elemp">元素节点对象</param>
 /// <param name="paras">XML参数</param>
 public static void CreateXMLFile(string fileFullName, XmlParameter rootp, XmlParameter elemp, 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, elemp.Name, null);
     ns = elemp.NamespaceOfPrefix == null ? "" : ln.GetNamespaceOfPrefix(elemp.NamespaceOfPrefix);
     foreach (AttributeParameter ap in elemp.Attributes)
     {
         XmlNode elemAtt = xDoc.CreateNode(XmlNodeType.Attribute, ap.Name, ns == "" ? null : ns);
         elemAtt.Value = ap.Value;
         ln.Attributes.SetNamedItem(elemAtt);
     }
     AppendChild(xDoc, ln, paras);
     root.AppendChild(ln);
     try
     {
         xDoc.Save(fileFullName);
     }
     catch
     {
         throw;
     }
 }