Export (0) Print
Expand All

XmlSchemaCollection.Add Method

Adds the given schema into the schema collection.

Overload List

Adds the XmlSchema to the collection.

[Visual Basic] Overloads Public Function Add(XmlSchema) As XmlSchema
[C#] public XmlSchema Add(XmlSchema);
[C++] public: XmlSchema* Add(XmlSchema*);
[JScript] public function Add(XmlSchema) : XmlSchema;

Adds all the namespaces defined in the given collection (including their associated schemas) to this collection.

[Visual Basic] Overloads Public Sub Add(XmlSchemaCollection)
[C#] public void Add(XmlSchemaCollection);
[C++] public: void Add(XmlSchemaCollection*);
[JScript] public function Add(XmlSchemaCollection);

Adds the schema located by the given URL into the schema collection.

[Visual Basic] Overloads Public Function Add(String, String) As XmlSchema
[C#] public XmlSchema Add(string, string);
[C++] public: XmlSchema* Add(String*, String*);
[JScript] public function Add(String, String) : XmlSchema;

Adds the schema contained in the XmlReader to the schema collection.

[Visual Basic] Overloads Public Function Add(String, XmlReader) As XmlSchema
[C#] public XmlSchema Add(string, XmlReader);
[C++] public: XmlSchema* Add(String*, XmlReader*);
[JScript] public function Add(String, XmlReader) : XmlSchema;

Adds the XmlSchema to the collection. The specified XmlResolver is used to resolve any external references.

[Visual Basic] Overloads Public Function Add(XmlSchema, XmlResolver) As XmlSchema
[C#] public XmlSchema Add(XmlSchema, XmlResolver);
[C++] public: XmlSchema* Add(XmlSchema*, XmlResolver*);
[JScript] public function Add(XmlSchema, XmlResolver) : XmlSchema;

Adds the schema contained in the XmlReader to the schema collection. The specified XmlResolver is used to resolve any external resources.

[Visual Basic] Overloads Public Function Add(String, XmlReader, XmlResolver) As XmlSchema
[C#] public XmlSchema Add(string, XmlReader, XmlResolver);
[C++] public: XmlSchema* Add(String*, XmlReader*, XmlResolver*);
[JScript] public function Add(String, XmlReader, XmlResolver) : XmlSchema;

Example

[Visual Basic, C#, C++] The following example adds a schema to the collection. An XmlUrlResolver is passed to the Add method which sets the necessary credentials required to access any external resources referenced in the schema.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Add. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Dim sc as XmlSchemaCollection = new XmlSchemaCollection()
AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack

' Create a resolver with the necessary credentials.
Dim resolver as XmlUrlResolver = new XmlUrlResolver()
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

' Add the new schema to the collection.
sc.Add(nothing, new XmlTextReader("sample.xsd"), resolver)

[C#] 
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);

// Create a resolver with the necessary credentials.
XmlUrlResolver resolver = new XmlUrlResolver();
resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Add the new schema to the collection.
sc.Add(null, new XmlTextReader("sample.xsd"), resolver);

[C++] 
XmlSchemaCollection* sc = new XmlSchemaCollection();
sc->ValidationEventHandler += new ValidationEventHandler(0, Sample::ValidationCallBack);

// Create a resolver with the necessary credentials.
XmlUrlResolver* resolver = new XmlUrlResolver();
System::Net::NetworkCredential* nc;
nc = new System::Net::NetworkCredential(UserName,SecurelyStoredPassword,Domain);  
resolver->Credentials = nc;

// Add the new schema to the collection.
sc->Add(0, new XmlTextReader(S"sample.xsd"), resolver);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

XmlSchemaCollection Class | XmlSchemaCollection Members | System.Xml.Schema Namespace

Show:
© 2014 Microsoft