예제 #1
0
        // 加入一个新元素
        // 本函数将依照prefix和URI对已经有的所有元素查重,如果遇到重复的,不会加入
        // parameters:
        //		bCheckPrefixDup	是否对prefix也单独查重。如果==true,当prefix重,即便URI不重也不让加入
        // return:
        //		true	prefix和URI完全相同的元素已存在, 未加入新元素
        //		false	没有遇到重复的事项,新元素成功加入
        public bool Add(string strPrefix,
                        string strURI,
                        bool bCheckPrefixDup)
        {
            Debug.Assert(strPrefix != null, "strPrefix参数不能为null");

            Debug.Assert(strURI != "" && strURI != null, "strURI参数不能为null");

            for (int i = 0; i < this.Count; i++)
            {
                NamespaceItem item = (NamespaceItem)(this[i]);
                if (bCheckPrefixDup == true &&
                    item.Prefix == strPrefix)
                {
                    return(true);
                }

                if (item.Prefix == strPrefix &&
                    item.URI == strURI)
                {
                    return(true);
                }
            }

            NamespaceItem newItem = new NamespaceItem();

            newItem.Prefix = strPrefix;
            newItem.URI    = strURI;
            this.Add(newItem);
            return(false);
        }
예제 #2
0
        // 假定nsColl中的信息即将还原为xml的属性字符串,插入element节点的属性集合中,
        // 本函数为确保不会发生属性重名的错误,而特意对nsColl去重
        public static void RemoveAttributeDup(ElementItem element,
                                              ref NamespaceItemCollection nsColl)
        {
            if (nsColl.Count == 0)
            {
                return;
            }

            // 对基准元素的属性进行一次去重操作
            if (element.attrs != null)
            {
                for (int i = 0; i < nsColl.Count; i++)
                {
                    NamespaceItem item = (NamespaceItem)nsColl[i];

                    string strAttrString = item.AttrName;

                    bool bOccurNamespaceAttr = false;
                    foreach (AttrItem attr in element.attrs)
                    {
                        if (attr.IsNamespace == false)
                        {
                            continue;
                        }

                        bOccurNamespaceAttr = true;

                        if (attr.Name == strAttrString)
                        {
                            nsColl.RemoveAt(i);
                            i--;
                            break;
                        }
                    }

                    if (bOccurNamespaceAttr == false)
                    {
                        break;                          // 说明element.attrs集合中,全部是普通类型的属性,没有名字空间型的属性,那样就意味着不用去重了
                    }
                }
            }
        }
예제 #3
0
		// 加入一个新元素
		// 本函数将依照prefix和URI对已经有的所有元素查重,如果遇到重复的,不会加入
		// parameters:
		//		bCheckPrefixDup	是否对prefix也单独查重。如果==true,当prefix重,即便URI不重也不让加入
		// return:
		//		true	prefix和URI完全相同的元素已存在, 未加入新元素
		//		false	没有遇到重复的事项,新元素成功加入
		public bool Add(string strPrefix,
			string strURI,
			bool bCheckPrefixDup)
		{
			Debug.Assert(strPrefix != null,"strPrefix参数不能为null");

			Debug.Assert(strURI != "" && strURI != null,"strURI参数不能为null");

			for(int i=0;i<this.Count;i++)
			{
				NamespaceItem item = (NamespaceItem)(this[i]);
				if (bCheckPrefixDup == true
					&& item.Prefix == strPrefix)
					return true;

				if (item.Prefix == strPrefix
					&& item.URI == strURI)
					return true;
			}

			NamespaceItem newItem = new NamespaceItem();
			newItem.Prefix = strPrefix;
			newItem.URI = strURI;
			this.Add(newItem);
			return false;
		}