XmlSchemaCollection Class
TOC
Collapse the table of content
Expand the table of content

XmlSchemaCollection Class

 
Note: This API is now obsolete.

Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. The XmlSchemaCollection class class is obsolete. Use XmlSchemaSet instead.

Namespace:   System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

System.Object
  System.Xml.Schema.XmlSchemaCollection

[ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202")]
public sealed class XmlSchemaCollection : ICollection, IEnumerable

NameDescription
System_CAPS_pubmethodXmlSchemaCollection()

Initializes a new instance of the XmlSchemaCollection class.

System_CAPS_pubmethodXmlSchemaCollection(XmlNameTable)

Initializes a new instance of the XmlSchemaCollection class with the specified XmlNameTable. The XmlNameTable is used when loading schemas.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of namespaces defined in this collection.

System_CAPS_pubpropertyItem[String]

Gets the XmlSchema associated with the given namespace URI.

System_CAPS_pubpropertyNameTable

Gets the default XmlNameTable used by the XmlSchemaCollection when loading new schemas.

NameDescription
System_CAPS_pubmethodAdd(String, String)

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

System_CAPS_pubmethodAdd(String, XmlReader)

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

System_CAPS_pubmethodAdd(String, XmlReader, XmlResolver)

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

System_CAPS_pubmethodAdd(XmlSchema)

Adds the XmlSchema to the collection.

System_CAPS_pubmethodAdd(XmlSchema, XmlResolver)

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

System_CAPS_pubmethodAdd(XmlSchemaCollection)

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

System_CAPS_pubmethodContains(String)

Gets a value indicating whether a schema with the specified namespace is in the collection.

System_CAPS_pubmethodContains(XmlSchema)

Gets a value indicating whether the targetNamespace of the specified XmlSchema is in the collection.

System_CAPS_pubmethodCopyTo(XmlSchema[], Int32)

Copies all the XmlSchema objects from this collection into the given array starting at the given index.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Provides support for the "for each" style iteration over the collection of schemas.

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubeventValidationEventHandler

Sets an event handler for receiving information about the XDR and XML schema validation errors.

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

Schemas are loaded using the Add method, at which time the schema is associated with a namespace Uniform Resource Identifier (URI). For XML Schemas, this will typically be the targetNamespace property of the schema.

Although this class stores both XML Schemas and XDR schemas, any method and property that takes or returns an XmlSchema applies to XML Schemas only.

This version of the product supports the World Wide Web Consortium (W3C) XML Schema recommendation located at http://www.w3.org/TR/xmlschema-1 and http://www.w3.org/TR/xmlschema-2. An XML Schema must reference the W3C Schema namespace http://www.w3.org/2001/XMLSchema in its schema element. See the Add method for an example.

XmlSchemaCollection can be used by XmlValidatingReader for efficient data validation.

System_CAPS_importantImportant

The XmlSchemaCollection class is obsolete in the Microsoft .NET Framework version 2.0 and has been replaced by the XmlSchemaSet class.

The following example validates an XML document using the XmlSchemaCollection.

using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;

public class ValidXSD {

  public static void Main() {
    XmlSchemaCollection sc = new XmlSchemaCollection();
    sc.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
    sc.Add(null, "books.xsd");

    if(sc.Count > 0)
    {
      XmlTextReader tr = new XmlTextReader("notValidXSD.xml");
      XmlValidatingReader rdr = new XmlValidatingReader(tr);

      rdr.ValidationType = ValidationType.Schema;
      rdr.Schemas.Add(sc);
      rdr.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
      while (rdr.Read());
    }

  }

  private static void ValidationCallBack(object sender, ValidationEventArgs e) {
    Console.WriteLine("Validation Error: {0}", e.Message);
  }
}

.NET Framework
Available since 1.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft