SoFunction
Updated on 2025-04-12

+XML operation base class (modify, delete, add, create)


#region Create an XML document
        /**************************************************
* Object Name: XmlObject
* Function description: Create an XML document
* Use the column:
*
         *          string xmlPath = ("");
         *          XmlObject obj = new XmlObject();
Creating a root node
         *          ("root");
*
         *          //("root", "Node");
*
*                  //("root", "Node" and "Node with Value");
*                  //Create a node with only attributes
*                //("root", "Node", "Attribe", "Attribute Value");
*                     //Create a node with only two attribute values
*                //("root", "Node", "Attribe", "Attribute value", "Attribe2", "Attribute value 2");
*
*                // ("root", "Node", "Attribe", "Attribute Value", "Node Value");
*                   /Insert a node with two attribute values ​​in the current node
*               ("root", "Node", "Attribe", "Attribute value", "Attribe2", "Attribute value 2", "Node value");
         *          (xmlPath);
         *          ();        
         ************************************************/


#region Create an XML document with only declarations and root nodes
        /// <summary>
/// Create an XML document with only declarations and root nodes
        /// </summary>
        /// <param name="root"></param>
        public void CreateXmlRoot(string root)
        {
//Additional paragraph for adding XML
            xmlNode = (, "", "");
            (xmlNode);
//Add a root element
            xmlElem = ("", root, "");
            (xmlElem);

        }
        #endregion

#region Insert an empty node under the current node
        /// <summary>
/// Insert an empty node under the current node
        /// </summary>
/// <param name="mainNode">Current node path</param>
/// <param name="node">Node Name</param>
        public void CreatXmlNode(string mainNode,string node)
        {
            XmlNode MainNode = (mainNode);
            XmlElement objElem = (node);            
            (objElem);
        }
        #endregion

#region Insert a node with only value in the current node
        /// <summary>
/// Insert a node with only value in the current node
        /// </summary>
/// <param name="mainNode">Current node</param>
/// <param name="node">New Node</param>
/// <param name="content">New node value</param>
        public void CreatXmlNode(string mainNode, string node, string content)
        {
            XmlNode MainNode = (mainNode);
            XmlElement objElem = (node);
             = content;
            (objElem);
        }
        #endregion

#region Insert a node with only attribute values ​​in the current node
        /// <summary>
/// Insert a node with only attribute values ​​in the current node
        /// </summary>
/// <param name="MainNode">Current node or path</param>
/// <param name="Node">New Node</param>
/// <param name="Attrib">New node attribute name</param>
/// <param name="AttribValue">New node attribute value</param>
        public void CreatXmlNode(string MainNode, string Node, string Attrib, string AttribValue)
        {
            XmlNode mainNode = (MainNode);
            XmlElement objElem = (Node);
            (Attrib, AttribValue);
            (objElem);
        }       
        #endregion

#region Create a node with a node value with an attribute value
        /// <summary>
/// Create a node with a node value with an attribute value
        /// </summary>
/// <param name="MainNode">Current node or path</param>
/// <param name="Node">Node Name</param>
/// <param name="Attrib">Attribute name</param>
/// <param name="AttribValue">Attribute value</param>
/// <param name="Content">Node Transmission</param>
        public void CreatXmlNode(string MainNode, string Node, string Attrib, string AttribValue,string Content)
        {
            XmlNode mainNode = (MainNode);
            XmlElement objElem = (Node);
            (Attrib, AttribValue);
             = Content;
            (objElem);
        }       
        #endregion      

#region Insert a node with only 2 attribute values ​​in the current node
        /// <summary>
/// Insert a node with only 2 attribute values ​​in the current node
        /// </summary>
/// <param name="MainNode">Current node or path</param>
/// <param name="Node">Node Name</param>
/// <param name="Attrib">Attribute name 1</param>
/// <param name="AttribValue">Attribute value one</param>
/// <param name="Attrib2">Attribute Name 2</param>
/// <param name="AttribValue2">Attribute value two</param>
        public void CreatXmlNode(string MainNode, string Node, string Attrib, string AttribValue,string Attrib2,string AttribValue2)
        {
            XmlNode mainNode = (MainNode);
            XmlElement objElem = (Node);
            (Attrib, AttribValue);
            (Attrib2, AttribValue2);
            (objElem);
        }
        #endregion

#region Insert node with two attributes in the current node
        /// <summary>
/// Insert a node with two attributes in the current node
        /// </summary>
/// <param name="MainNode">Current node or path</param>
/// <param name="Node">Node Name</param>
/// <param name="Attrib">Attribute name 1</param>
/// <param name="AttribValue">Attribute value one</param>
/// <param name="Attrib2">Attribute Name 2</param>
/// <param name="AttribValue2">Attribute value two</param>
/// <param name="Content">Node Value</param>
        public void CreatXmlNode(string MainNode, string Node, string Attrib, string AttribValue, string Attrib2, string AttribValue2,string Content)
        {
            XmlNode mainNode = (MainNode);
            XmlElement objElem = (Node);
            (Attrib, AttribValue);
            (Attrib2, AttribValue2);
             = Content;
            (objElem);
        }
        #endregion

#region Save Xml
        /// <summary>
///Save Xml
        /// </summary>
/// <param name="path">Save current path</param>
        public void XmlSave(string path)
        {
            (path);
        }

        #endregion

        #endregion

#region Read child node values ​​based on parent node attribute value
        /**************************************************
* Function name: GetSubElementByAttribute(string XmlPath, string FatherElenetName, string AttributeName, int AttributeIndex, int ArrayLength)
* Function description: Read child node values ​​according to parent node attribute value
*
* Applicable to Xml:
         * <root>
      *   <page name="/">
*      <title>Domain name registration, virtual hosting, corporate post office, server hosting, website space rental|---First Business</title>
*      <keywords>Virtual hosting, domain name registration, server hosting, Hangzhou, server rental,</keywords>
*       <description>Description</description>
      *    </page>
         * </root>
         *           ArrayList al = new ArrayList();
         *           al = (XmlPath, "page", "/", 0, 3);
         *           for (int i = 0; i < ; i++)
         *           {
         *               (al[i].ToString());
         *               ("<br>");
         *           }
         ************************************************/
        /// <summary>
/// Read word node value according to parent node attribute
        /// </summary>
/// <param name="XmlPath">xml path</param>
/// <param name="FatherElenetName">Parent node name</param>
/// <param name="AttributeName">Attribute Value</param>
/// <param name="AttributeIndex">Attribute Index</param>
/// <param name="ArrayLength">Length of node array to be returned</param>
        /// <returns></returns>
        public static  GetSubElementByAttribute(string XmlPath, string FatherElenetName, string AttributeName, int AttributeIndex, int ArrayLength)
        {
             al = new ();
            XmlDocument docXml = new XmlDocument();
            (@XmlPath);
            XmlNodeList xn = ;
//Travel over the first layer of nodes
            foreach (XmlElement element in xn)
            {
//Determine whether the parent node is a specified node
                if ( == FatherElenetName)
                {
//Determine whether the index of the parent node attribute is greater than the specified index
                    if ( < AttributeIndex)
                        return null;
//Determine whether the property value of the parent node is equal to the specified property
                    if ([AttributeIndex].Value == AttributeName)
                    {
                        XmlNodeList xx = ;
                        if ( > 0)
                        {
                            for (int i = 0; i < ArrayLength & i < ; i++)
                            {
                                (xx[i].InnerText);
                            }
                        }
                    }

                }
            }
            return al;
        }

        #endregion

#region Read child node values ​​according to node attributes (more resource saving mode)
        /**************************************************
* Function name: GetSubElementByAttribute(string XmlPath, string FatherElement, string AttributeName, string AttributeValue, int ArrayLength)
* Function description: Read child node values ​​according to parent node attribute value
*
* Applicable to Xml:
         * <root>
      *   <page name="/">
*      <title>Domain name registration, virtual hosting, corporate post office, server hosting, website space rental|---First Business</title>
*      <keywords>Virtual hosting, domain name registration, server hosting, Hangzhou, server rental,</keywords>
*       <description>Description</description>
      *    </page>
         * </root>
         *           ArrayList al = new ArrayList();
         *           al = (XmlPath, "page", "@name", "/", 3);
         *           for (int i = 0; i < ; i++)
         *           {
         *               (al[i].ToString());
         *               ("<br>");
         *           }
         ************************************************/
        /// <summary>
/// Read child node values ​​according to node attributes (more resource saving mode)
        /// </summary>
/// <param name="XmlPath">xml path</param>
/// <param name="FatherElement">Parent node value</param>
/// <param name="AttributeName">Attribute Name</param>
/// <param name="AttributeValue">Attribute Value</param>
/// <param name="ArrayLength">Returned array length</param>
        /// <returns></returns>
        public static   GetSubElementByAttribute(string XmlPath, string FatherElement, string AttributeName, string AttributeValue, int ArrayLength)
        {
             al = new ();
            XmlDocument docXml = new XmlDocument();
            (@XmlPath);
            XmlNodeList xn;
            xn = ("//" + FatherElement + "[" + @AttributeName + "='" + AttributeValue + "']");
            XmlNodeList xx = (0).ChildNodes;
            for (int i = 0; i < ArrayLength & i < ; i++)
            {

                ((i).InnerText);
            }
            return al;

        }
        #endregion
    }
}