zoukankan      html  css  js  c++  java
  • 创建 XML 类

        //========================================创建 XML  类  ===========================================================
        #region InsertNode
        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string ChildNode, string Element, string Content)
        {
            //插入一节点和此节点的一子节点。
            //XmlNode objRootNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objRootNode = xmlNodeList.Item(0);
            XmlElement objChildNode = objXmlDoc.CreateElement(ChildNode);
            objRootNode.AppendChild(objChildNode);//插入节点
            XmlElement objElement = objXmlDoc.CreateElement(Element);
            objElement.InnerText = Content;
            objChildNode.AppendChild(objElement);//插入子节点
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string Element, string Attrib, string AttribContent, string Content)
        {
            //插入一个节点,带一属性。
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            XmlElement objElement = objXmlDoc.CreateElement(Element);
            objElement.SetAttribute(Attrib, AttribContent);
            objElement.InnerText = Content;
            objNode.AppendChild(objElement);
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string Element, string Content)
        {
            //插入一个节点,不带属性。
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            XmlElement objElement = objXmlDoc.CreateElement(Element);
            objElement.InnerText = Content;
            objNode.AppendChild(objElement);
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string[] Element, string[] Content)
        {
            //插入一个节点,不带属性。
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            for (int i = 0; i < Element.Length; i++)
            {
                XmlElement objElement = objXmlDoc.CreateElement(Element[i]);
                objElement.InnerText = Content[i];
                objNode.AppendChild(objElement);
            }
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, List<ArrayList> listElement)
        {
            //插入一个节点,不带属性。
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            for (int i = 0; i < listElement[0].Count; i++)
            {
                XmlElement objElement = objXmlDoc.CreateElement(listElement[0][i].ToString());
                objElement.InnerText = listElement[1][i].ToString();
                objNode.AppendChild(objElement);
            }
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string elementName, string[] Element, string[] Content)
        {
            //插入一个节点,不带属性。
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            XmlElement xmlElement = objXmlDoc.CreateElement(elementName);
            for (int i = 0; i < Element.Length; i++)
            {
                XmlElement objElement = objXmlDoc.CreateElement(Element[i]);
                objElement.InnerText = Content[i];
                xmlElement.AppendChild(objElement);
            }
            objNode.AppendChild(xmlElement);
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string elementName, List<ArrayList> listElement)
        {
            //插入一个节点,不带属性。
            if (listElement.Count > 0)
            {
                XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
                XmlNode objNode = xmlNodeList.Item(0);
                XmlElement xmlElement = objXmlDoc.CreateElement(elementName);

                for (int i = 0; i < listElement[0].Count; i++)
                {
                    XmlElement objElement = objXmlDoc.CreateElement(listElement[0][i].ToString());
                    objElement.InnerText = listElement[1][i].ToString();
                    xmlElement.AppendChild(objElement);
                }
                objNode.AppendChild(xmlElement);
            }
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string mainNode, string elementName, string[] arrAttributeName, string[] arrAttributeContent, string elementContent)
        {
            //XmlNode objNode = objXmlDoc.SelectSingleNode(mainNode);
            XmlNodeList xmlNodeList = objXmlDoc.GetElementsByTagName(mainNode);
            XmlNode objNode = xmlNodeList.Item(0);
            XmlElement objElement = objXmlDoc.CreateElement(elementName);
            for (int i = 0; i <= arrAttributeName.GetUpperBound(0); i++)
            {
                objElement.SetAttribute(arrAttributeName[i], arrAttributeContent[i]);
            }
            objElement.InnerText = elementContent;
            objNode.AppendChild(objElement);
            return objXmlDoc;
        }

        public XmlDocument InsertNode(XmlDocument objXmlDoc, string elementName, string[] arrAttributeName, string[] arrAttributeContent, string elementContent)
        {
            XmlElement objElement = objXmlDoc.CreateElement(elementName);
            for (int i = 0; i <= arrAttributeName.GetUpperBound(0); i++)
            {
                objElement.SetAttribute(arrAttributeName[i], arrAttributeContent[i]);
            }
            objElement.InnerText = elementContent;
            objXmlDoc.AppendChild(objElement);
            return objXmlDoc;
        }
        #endregion
        //=====================================================================================================================

  • 相关阅读:
    153. Find Minimum in Rotated Sorted Array
    228. Summary Ranges
    665. Non-decreasing Array
    661. Image Smoother
    643. Maximum Average Subarray I
    4.7作业
    面向对象编程
    常用模块3
    3.31作业
    常用模块2
  • 原文地址:https://www.cnblogs.com/xsmhero/p/1904735.html
Copyright © 2011-2022 走看看