Exemple #1
0
        /// <summary>
        /// 删除默认节点
        /// </summary>
        /// <param name="key"></param>
        public static void RemoveSectionKey(string key)
        {
            string SectionName = "appSettings";

            //导入配置文件
            System.Xml.XmlDocument doc = loadConfigDocument();

            //重新取得 节点名

            System.Xml.XmlNode node = doc.SelectSingleNode("//" + SectionName);

            try
            {
                if (node == null)
                {
                    throw new InvalidOperationException(SectionName + " section not found in config file.");
                }
                else
                {
                    // 用 'add' 方法格式 key和value
                    node.RemoveChild(node.SelectSingleNode(string.Format("//add[@key='{0}']", key)));
                    doc.Save(getConfigFilePath());
                }
            }
            catch (NullReferenceException e)
            {
                throw new Exception(string.Format("The key {0} does not exist.", key), e);
            }
        }
Exemple #2
0
 /// <summary>
 /// 删除一个XML节点的所有的子节点
 /// </summary>
 /// <param name="myNode">XML节点</param>
 public static void ClearChildNode(System.Xml.XmlNode myNode)
 {
     if (myNode != null)
     {
         while (myNode.FirstChild != null)
         {
             myNode.RemoveChild(myNode.FirstChild);
         }
     }
 }
Exemple #3
0
        /// <summary>
        /// 设置菜单项所属的菜单组。
        /// </summary>
        /// <param name="MenuItemID">菜单项 ID。</param>
        /// <param name="MenuGroupID">新的菜单组 ID。</param>
        /// <exception cref="Thinksea.NotFoundException">没有找到指定的记录。</exception>
        public void MoveMenuItem(string MenuItemID, string MenuGroupID)
        {
            System.Xml.XmlNode MenuItemNode     = null;
            System.Xml.XmlNode OldMenuGroupNode = null;
            #region 获取当前所在的菜单组。
            {
                System.Xml.XmlNodeList xnl = this.xmlDocument.SelectNodes("/Menu/MenuGroup/MenuItem");
                foreach (System.Xml.XmlNode tmp in xnl)
                {
                    if (tmp.Attributes["ID"] != null && tmp.Attributes["ID"].Value == MenuItemID)
                    {
                        MenuItemNode     = tmp;
                        OldMenuGroupNode = tmp.ParentNode;
                    }
                }
                if (OldMenuGroupNode == null || MenuItemNode == null)
                {
                    throw new Thinksea.NotFoundException("没有找到指定的记录。");
                }
            }
            #endregion

            System.Xml.XmlNode NewMenuGroupNode = null;
            #region 获取新的菜单组。
            {
                System.Xml.XmlNodeList xnl = this.xmlDocument.SelectNodes("/Menu/MenuGroup");
                foreach (System.Xml.XmlNode tmp in xnl)
                {
                    if (tmp.Attributes["ID"] != null && tmp.Attributes["ID"].Value == MenuGroupID)
                    {
                        NewMenuGroupNode = tmp;
                        break;
                    }
                }

                if (NewMenuGroupNode == null)
                {
                    throw new Thinksea.NotFoundException("没有找到指定的菜单组。");
                }
            }
            #endregion

            #region 排出所设置的菜单组 ID 与当前所属的菜单组 ID 相同的情况。
            {
                if (OldMenuGroupNode.Attributes["ID"] != null && OldMenuGroupNode.Attributes["ID"].Value == MenuGroupID)
                {
                    return;
                }
            }
            #endregion

            OldMenuGroupNode.RemoveChild(MenuItemNode);
            NewMenuGroupNode.AppendChild(MenuItemNode);
        }
Exemple #4
0
 /// <summary>
 /// 删除默认节点
 /// </summary>
 /// <param name="key">key名</param>
 public static void RemoveSectionKey(string key)
 {
     System.Xml.XmlDocument doc  = LoadConfigDocument;
     System.Xml.XmlNode     node = doc.SelectSingleNode("//" + appSettingsName);
     if (node == null)
     {
         return;
     }
     node.RemoveChild(node.SelectSingleNode(string.Format("//add[@key='{0}']", key)));
     doc.Save(getConfigFilePath);
 }
        private System.Xml.XmlNode GetSheetsRootNodeAndRemoveChildrens(System.Xml.XmlDocument contentXml, System.Xml.XmlNamespaceManager nmsManager)
        {
            System.Xml.XmlNodeList tableNodes = this.GetTableNodes(contentXml, nmsManager);

            System.Xml.XmlNode sheetsRootNode = tableNodes.Item(0).ParentNode;
            // remove sheets from template file
            foreach (System.Xml.XmlNode tableNode in tableNodes)
            {
                sheetsRootNode.RemoveChild(tableNode);
            }

            return(sheetsRootNode);
        }
        protected virtual void WriteToXmlElement(System.Xml.XmlElement xmlElement, PersistenceFlags flags)
        {
            //settings
            System.Xml.XmlNode xmlsettings = xmlElement.SelectSingleNode("settings");
            if (xmlsettings == null)
            {
                xmlsettings = xmlElement.OwnerDocument.CreateElement("settings");
                xmlElement.AppendChild(xmlsettings);
            }
            //items
            System.Xml.XmlNode xmlitems = xmlsettings.SelectSingleNode("items");
            if (xmlitems == null)
            {
                xmlitems = xmlsettings.OwnerDocument.CreateElement("items");
                xmlsettings.AppendChild(xmlitems);
                xmlitems.Attributes.Append(xmlitems.OwnerDocument.CreateAttribute("schemaversion"));
                xmlitems.Attributes["schemaversion"].Value = "1";
            }

            foreach (PersistableItem item in m_Dictionary.Values)
            {
                string             xPath   = string.Format("item[@name='{0}' and @type='{1}' and @schemaversion='1']", item.Name, item.Type.FullName);
                System.Xml.XmlNode xmlitem = xmlitems.SelectSingleNode(xPath);

                if ((flags & PersistenceFlags.OnlyChanges) == PersistenceFlags.OnlyChanges &&
                    item.IsChanged == false)
                {                 //remove item
                    if (xmlitem != null)
                    {
                        xmlitems.RemoveChild(xmlitem);
                    }
                }
                else                 //add item
                {
                    if (xmlitem == null)
                    {
                        xmlitem = xmlitems.OwnerDocument.CreateElement("item");
                        xmlitems.AppendChild(xmlitem);

                        xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("name"));
                        xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("type"));
                        xmlitem.Attributes.Append(xmlitem.OwnerDocument.CreateAttribute("schemaversion"));

                        xmlitem.Attributes["name"].Value          = item.Name;
                        xmlitem.Attributes["type"].Value          = item.Type.FullName;
                        xmlitem.Attributes["schemaversion"].Value = "1";
                    }
                    xmlitem.InnerText = item.Validator.ValueToString(item.Value);
                }
            }
        }
Exemple #7
0
        public bool RemoveElement(string xpath)
        {
            bool bResult = false;

            System.Xml.XmlNode oXmlNode = _XmlDocument.SelectSingleNode(xpath);
            if (oXmlNode.NodeType == System.Xml.XmlNodeType.Element)
            {
                System.Xml.XmlNode Parent = oXmlNode.ParentNode;
                Parent.RemoveChild(oXmlNode);
                bResult = true;
            }

            return(bResult);
        }
Exemple #8
0
 /// <summary>
 /// 将指定的菜单项下降一个位置。
 /// </summary>
 /// <param name="ID">菜单项 ID。</param>
 public void SendMenuItemToBack(string ID)
 {
     System.Xml.XmlNodeList xnl = this.xmlDocument.SelectNodes("/Menu/MenuGroup/MenuItem");
     foreach (System.Xml.XmlNode tmp in xnl)
     {
         if (tmp.Attributes["ID"] != null && tmp.Attributes["ID"].Value == ID)
         {
             System.Xml.XmlNode ParentNode  = tmp.ParentNode;
             System.Xml.XmlNode NextSibling = tmp.NextSibling;
             if (NextSibling != null && NextSibling != null)
             {
                 ParentNode.RemoveChild(tmp);
                 ParentNode.InsertAfter(tmp, NextSibling);
                 return;
             }
         }
     }
 }
Exemple #9
0
 /// <summary>
 /// 将指定的菜单组提升一个位置。
 /// </summary>
 /// <param name="ID">菜单组 ID。</param>
 public void SendMenuGroupToPre(string ID)
 {
     System.Xml.XmlNodeList xnl = this.xmlDocument.SelectNodes("/Menu/MenuGroup");
     foreach (System.Xml.XmlNode tmp in xnl)
     {
         if (tmp.Attributes["ID"] != null && tmp.Attributes["ID"].Value == ID)
         {
             System.Xml.XmlNode ParentNode      = tmp.ParentNode;
             System.Xml.XmlNode PreviousSibling = tmp.PreviousSibling;
             if (ParentNode != null && PreviousSibling != null)
             {
                 ParentNode.RemoveChild(tmp);
                 ParentNode.InsertBefore(tmp, PreviousSibling);
                 return;
             }
         }
     }
 }