⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlmanage.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    if (string.Compare(node2.GetType().Name, "XmlElement", true) != 0)
                    {
                        continue;
                    }
                    flag = true;
                    bool flag2 = false;
                    if (outype > 0)
                    {
                        foreach (System.Xml.XmlNode node3 in list3)
                        {
                            if (string.Compare(node3.Name, node2.Name, true) == 0)
                            {
                                XmlElement element = (XmlElement) node3;
                                element.SetAttribute("pe_tempshownum", (Convert.ToInt32(element.GetAttribute("pe_tempshownum")) + 1).ToString());
                                flag2 = true;
                            }
                        }
                    }
                    if (!flag2)
                    {
                        ((XmlElement) node2).SetAttribute("pe_tempshownum", "1");
                        list3.Add(node2);
                    }
                }
                if (flag)
                {
                    item.Type = "havechile";
                }
                else
                {
                    item.Type = "nochile";
                }
                XmlElement element3 = (XmlElement) node;
                if (element3.HasAttribute("pe_tempshownum"))
                {
                    item.Repnum = Convert.ToInt32(element3.GetAttribute("pe_tempshownum").ToString());
                }
                list.Add(item);
                foreach (System.Xml.XmlNode node4 in list3)
                {
                    int num3 = 0;
                    if (list3.IndexOf(node4) == 0)
                    {
                        num3 = 1;
                    }
                    else if (list3.IndexOf(node4) == (list3.Count - 1))
                    {
                        num3 = 2;
                    }
                    if (string.Compare(node4.Name, "#text", true) > 0)
                    {
                        string str = xpath + "/" + node.Name;
                        foreach (XmlScheme scheme2 in GetXmlTree(node4, num, outdeep, str, outype, num3))
                        {
                            list.Add(scheme2);
                        }
                    }
                }
            }
            return list;
        }

        public static XmlManage Instance(string fileName, XmlType type)
        {
            XmlManage manage = new XmlManage();
            switch (type)
            {
                case XmlType.None:
                    manage.Load(fileName);
                    return manage;

                case XmlType.File:
                    manage.Load(fileName);
                    return manage;

                case XmlType.Content:
                    manage.LoadXml(fileName);
                    return manage;
            }
            return manage;
        }

        private void Load(string fileName)
        {
            HttpContext current = HttpContext.Current;
            if (current != null)
            {
                this.filePath = current.Server.MapPath("~/" + fileName);
            }
            else
            {
                this.filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
            }
            this.xmlDoc.Load(this.filePath);
        }

        private void LoadXml(string xmlContent)
        {
            this.xmlDoc.LoadXml(xmlContent);
        }

        public static string ReadFileNode(string filepath, string nodename)
        {
            if ((!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(nodename)) && System.IO.File.Exists(filepath))
            {
                XmlDocument document = new XmlDocument();
                try
                {
                    document.Load(filepath);
                }
                catch (XmlException)
                {
                    return string.Empty;
                }
                try
                {
                    return document.SelectSingleNode(nodename).InnerText;
                }
                catch (NullReferenceException)
                {
                    return string.Empty;
                }
            }
            return string.Empty;
        }

        public bool Remove(string nodeName)
        {
            try
            {
                System.Xml.XmlNode oldChild = this.xmlDoc.SelectSingleNode(nodeName);
                oldChild.ParentNode.RemoveChild(oldChild);
            }
            catch (NullReferenceException)
            {
                return false;
            }
            return true;
        }

        public void Save(string fileName)
        {
            HttpContext current = HttpContext.Current;
            if (current != null)
            {
                this.filePath = current.Server.MapPath("~/" + fileName);
            }
            else
            {
                this.filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
            }
            this.xmlDoc.Save(this.filePath);
        }

        public static bool SaveFileNode(string filepath, string nodepath, string nodename, string nodevalue)
        {
            if (((!string.IsNullOrEmpty(filepath) && !string.IsNullOrEmpty(nodepath)) && !string.IsNullOrEmpty(nodename)) && System.IO.File.Exists(filepath))
            {
                XmlDocument document = new XmlDocument();
                try
                {
                    document.Load(filepath);
                    foreach (System.Xml.XmlNode node in document.SelectNodes(nodepath))
                    {
                        XmlNodeList list2 = node.SelectNodes(nodename);
                        if (list2.Count > 0)
                        {
                            foreach (System.Xml.XmlNode node2 in list2)
                            {
                                XmlElement element = (XmlElement) node2;
                                element.RemoveAll();
                                if (!string.IsNullOrEmpty(nodevalue))
                                {
                                    if (((nodevalue.IndexOf("<") > 0) || (nodevalue.IndexOf(">") > 0)) || (nodevalue.IndexOf("'") > 0))
                                    {
                                        XmlCDataSection section = document.CreateCDataSection(nodevalue);
                                        element.AppendChild(section);
                                        continue;
                                    }
                                    element.InnerText = nodevalue;
                                }
                            }
                            continue;
                        }
                        XmlElement newChild = document.CreateElement("", nodename, "");
                        if (((nodevalue.IndexOf("<") > 0) || (nodevalue.IndexOf(">") > 0)) || (nodevalue.IndexOf("'") > 0))
                        {
                            XmlCDataSection section2 = document.CreateCDataSection(nodevalue);
                            newChild.AppendChild(section2);
                        }
                        else
                        {
                            newChild.InnerText = nodevalue;
                        }
                        node.AppendChild(newChild);
                    }
                    document.Save(filepath);
                    return true;
                }
                catch (XmlException)
                {
                    return false;
                }
            }
            return false;
        }

        public string SelectNode(string nodeName)
        {
            System.Xml.XmlNode node = this.xmlDoc.SelectSingleNode(nodeName);
            if (node == null)
            {
                return string.Empty;
            }
            return node.OuterXml;
        }

        public bool SetAttributesValue(string nodeName, string key, string val)
        {
            System.Xml.XmlNode node = this.xmlDoc.SelectSingleNode(nodeName);
            if (node == null)
            {
                return false;
            }
            ((XmlElement) node).SetAttribute(key, val);
            return true;
        }

        public bool SetNodeValue(string nodeName, string val)
        {
            System.Xml.XmlNode node = this.xmlDoc.SelectSingleNode(nodeName);
            if (node == null)
            {
                return false;
            }
            node.InnerText = val;
            return true;
        }

        public IXPathNavigable XmlNode(string path)
        {
            return this.xmlDoc.SelectSingleNode(path);
        }

        public string Xml
        {
            get
            {
                StringWriter writer = new StringWriter();
                this.xmlDoc.Save(writer);
                string str = writer.ToString();
                writer.Dispose();
                return str;
            }
        }

        public IXPathNavigable XmlDoc
        {
            get
            {
                return this.xmlDoc;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -