예제 #1
0
        /// <summary>
        /// all extension elements that match a namespace/localname
        /// given will be removed and replaced with the new ones.
        /// the input array can contain several different
        /// namespace/localname combinations
        /// if the passed list is NULL or empty, this will just result
        /// in additions
        /// </summary>
        /// <param name="newList">a list of xmlnodes or IExtensionElementFactory objects</param>
        /// <returns>int - the number of deleted extensions</returns>
        public int ReplaceExtensions(ExtensionList newList)
        {
            int count = 0;

            // get rid of all of the old ones matching the specs
            if (newList != null)
            {
                foreach (Object ob in newList)
                {
                    string  localName = null;
                    string  ns        = null;
                    XmlNode node      = ob as XmlNode;
                    if (node != null)
                    {
                        localName = node.LocalName;
                        ns        = node.NamespaceURI;
                    }
                    else
                    {
                        IExtensionElementFactory ele = ob as IExtensionElementFactory;
                        if (ele != null)
                        {
                            localName = ele.XmlName;
                            ns        = ele.XmlNameSpace;
                        }
                    }

                    if (localName != null)
                    {
                        count += DeleteExtensions(localName, ns);
                    }
                }

                // now add the new ones
                foreach (IExtensionElementFactory ob in newList)
                {
                    ExtensionElements.Add(ob);
                }
            }

            return(count);
        }
예제 #2
0
        /// <summary>
        /// Finds all ExtensionElement based on it's local name
        /// and it's namespace. If namespace is NULL, allwhere
        /// the localname matches is found. If there are extensionelements that do
        /// not implment ExtensionElementFactory, they will not be taken into account
        /// Primary use of this is to find XML nodes
        /// </summary>
        /// <param name="arrList">the array to search through</param>
        /// <param name="localName">the xml local name of the element to find</param>
        /// <param name="ns">the namespace of the elementToPersist</param>
        /// <param name="arr">the array to fill</param>
        /// <returns>none</returns>
        public static ExtensionList FindExtensions(ExtensionList arrList, string localName, string ns, ExtensionList arr)
        {
            if (arrList == null)
            {
                throw new ArgumentNullException("arrList");
            }

            if (arr == null)
            {
                throw new ArgumentNullException("arr");
            }

            foreach (IExtensionElementFactory ob in arrList)
            {
                XmlNode node = ob as XmlNode;
                if (node != null)
                {
                    if (compareXmlNess(node.LocalName, localName, node.NamespaceURI, ns))
                    {
                        arr.Add(ob);
                    }
                }
                else
                {
                    // only if the elements do implement the ExtensionElementFactory
                    // do we know if it's xml name/namespace
                    IExtensionElementFactory ele = ob as IExtensionElementFactory;
                    if (ele != null)
                    {
                        if (compareXmlNess(ele.XmlName, localName, ele.XmlNameSpace, ns))
                        {
                            arr.Add(ob);
                        }
                    }
                }
            }

            return(arr);
        }