當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlSchemaObjectCollection.Insert方法代碼示例

本文整理匯總了C#中System.Xml.Schema.XmlSchemaObjectCollection.Insert方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlSchemaObjectCollection.Insert方法的具體用法?C# XmlSchemaObjectCollection.Insert怎麽用?C# XmlSchemaObjectCollection.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.Schema.XmlSchemaObjectCollection的用法示例。


在下文中一共展示了XmlSchemaObjectCollection.Insert方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddElement


//.........這裏部分代碼省略.........
                        if (col != null && col.Count > 0 ) 
                        {
                            xs = col[0] as XmlSchema;
                        }
                        xse = new XmlSchemaElement();
                        xse.Name = localName;
                        xs.Items.Add(xse);
                    }
                    else
                        bCreatingNewType = false;               

                }
                else
                {
                    xs = CreateXmlSchema(childURI);
                    if (prefix.Length!=0)
                        NamespaceManager.AddNamespace(prefix, childURI);
                    xse=new XmlSchemaElement();
                    xse.Name = localName;
                    xs.Items.Add(xse);  //add global element declaration only when creating new schema
                }
                if (parentSchema == null) 
                {
                    parentSchema = xs;
                    this.rootSchema = parentSchema;
                }

                if (childURI != parentSchema.TargetNamespace ) 
                {
                    bool add = true;

                    for (int i = 0; i < parentSchema.Includes.Count; ++i)
                    {
                        XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport;
                        if (import == null) 
                        {
                            continue;
                        }
                        //Debug.WriteLine(import.Schema.TargetNamespace);
                     
                        if (import.Namespace == childURI) 
                        {
                            add = false;
                        }
                    }
                    if (add) 
                    {
                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Schema = xs;
                        import.Namespace = childURI;
                        parentSchema.Includes.Add(import);
                    }      
                }
                returnedElement = xse;
                if (addLocation != null)
                {
                    if (childURI == parentSchema.TargetNamespace )
                    {
                        if (this.Occurrence == InferenceOption.Relaxed /*&& parentSchema.Items != addLocation*/) 
                        {
                            xse.MinOccurs = 0;
                        }
                        if (positionWithinCollection == -1) 
                        {
                            positionWithinCollection = addLocation.Add(xse);
                        }
                        else 
                        {
                            addLocation.Insert(positionWithinCollection, xse);
                        }
                    }
                    else
                    {
                        XmlSchemaElement elementReference = new XmlSchemaElement();
                        elementReference.RefName = new XmlQualifiedName(localName, childURI);
                        if (this.Occurrence == InferenceOption.Relaxed) 
                        {
                            elementReference.MinOccurs = 0;
                        }
                        if (positionWithinCollection == -1) 
                        {
                            positionWithinCollection = addLocation.Add(elementReference);
                        }
                        else 
                        {
                            addLocation.Insert(positionWithinCollection, elementReference);
                        }
                        returnedElement = elementReference;
                       /* if (childURI == XmlSchema.Namespace) 
                        {
                            schemaList.Add(new ReplaceList(addLocation, positionWithinCollection));
                        }*/
                    }
                }
           

                InferElement(xse, bCreatingNewType, xs);
            
                return returnedElement;
            }
開發者ID:krytht,項目名稱:DotNetReferenceSource,代碼行數:101,代碼來源:infer.cs

示例2: AddElement

 private XmlSchemaElement AddElement(string localName, string prefix, string childURI, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, int positionWithinCollection)
 {
     if (childURI == "http://www.w3.org/2001/XMLSchema")
     {
         throw new XmlSchemaInferenceException("SchInf_schema", 0, 0);
     }
     XmlSchemaElement item = null;
     XmlSchemaElement element2 = item;
     XmlSchema schema = null;
     bool bCreatingNewType = true;
     if (childURI == string.Empty)
     {
         childURI = null;
     }
     if ((parentSchema != null) && (childURI == parentSchema.TargetNamespace))
     {
         item = new XmlSchemaElement {
             Name = localName
         };
         schema = parentSchema;
         if ((schema.ElementFormDefault != XmlSchemaForm.Qualified) && (addLocation != null))
         {
             item.Form = XmlSchemaForm.Qualified;
         }
     }
     else if (this.schemaSet.Contains(childURI))
     {
         item = this.FindGlobalElement(childURI, localName, out schema);
         if (item == null)
         {
             ArrayList list = this.schemaSet.Schemas(childURI) as ArrayList;
             if ((list != null) && (list.Count > 0))
             {
                 schema = list[0] as XmlSchema;
             }
             item = new XmlSchemaElement {
                 Name = localName
             };
             schema.Items.Add(item);
         }
         else
         {
             bCreatingNewType = false;
         }
     }
     else
     {
         schema = this.CreateXmlSchema(childURI);
         if (prefix.Length != 0)
         {
             this.NamespaceManager.AddNamespace(prefix, childURI);
         }
         item = new XmlSchemaElement {
             Name = localName
         };
         schema.Items.Add(item);
     }
     if (parentSchema == null)
     {
         parentSchema = schema;
         this.rootSchema = parentSchema;
     }
     if (childURI != parentSchema.TargetNamespace)
     {
         bool flag2 = true;
         for (int i = 0; i < parentSchema.Includes.Count; i++)
         {
             XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport;
             if ((import != null) && (import.Namespace == childURI))
             {
                 flag2 = false;
             }
         }
         if (flag2)
         {
             XmlSchemaImport import2 = new XmlSchemaImport {
                 Schema = schema,
                 Namespace = childURI
             };
             parentSchema.Includes.Add(import2);
         }
     }
     element2 = item;
     if (addLocation != null)
     {
         if (childURI == parentSchema.TargetNamespace)
         {
             if (this.Occurrence == InferenceOption.Relaxed)
             {
                 item.MinOccurs = 0M;
             }
             if (positionWithinCollection == -1)
             {
                 positionWithinCollection = addLocation.Add(item);
             }
             else
             {
                 addLocation.Insert(positionWithinCollection, item);
             }
         }
//.........這裏部分代碼省略.........
開發者ID:pritesh-mandowara-sp,項目名稱:DecompliedDotNetLibraries,代碼行數:101,代碼來源:XmlSchemaInference.cs


注:本文中的System.Xml.Schema.XmlSchemaObjectCollection.Insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。