แก้ไข

แชร์ผ่าน


XmlSchemaObjectCollection.Add(XmlSchemaObject) Method

Definition

Adds an XmlSchemaObject to the XmlSchemaObjectCollection.

public:
 int Add(System::Xml::Schema::XmlSchemaObject ^ item);
public int Add (System.Xml.Schema.XmlSchemaObject item);
member this.Add : System.Xml.Schema.XmlSchemaObject -> int
Public Function Add (item As XmlSchemaObject) As Integer

Parameters

Returns

The index at which the item has been added.

Exceptions

index is less than zero.

-or-

index is greater than Count.

The XmlSchemaObject parameter specified is not of type XmlSchemaExternal or its derived types XmlSchemaImport, XmlSchemaInclude, and XmlSchemaRedefine.

Remarks

If Count already equals the capacity, the capacity of list is doubled by automatically reallocating the internal array and copying the existing elements to the new array before the new element is added.

If Count is less than the capacity, this method is an 0(1) operation. If the capacity needs to be increased to accommodate the new element, this method becomes an 0(n) operation, where n is Count.

The Add method expects only XmlSchemaExternal and its derived types (XmlSchemaImport, XmlSchemaInclude, and XmlSchemaRedefine) as parameters. The following example illustrates adding an included schema to the Includes collection of an existing XmlSchema object.

Dim schema As XmlSchema = New XmlSchema()  

Dim textReader As XmlTextReader = New XmlTextReader("include.xsd")  
Dim includeSchema As XmlSchema = XmlSchema.Read(textReader, null)  

Dim include As XmlSchemaInclude = New XmlSchemaInclude()  
include.Schema = includeSchema;  
schema.Includes.Add(include);  
XmlSchema schema = new XmlSchema();  

XmlTextReader textReader = new XmlTextReader("include.xsd");  
XmlSchema includeSchema = XmlSchema.Read(textReader, null);  

XmlSchemaInclude include = new XmlSchemaInclude();  
include.Schema = includeSchema;  
schema.Includes.Add(include);  

Applies to