XmlSchemaCollection Class
NOTE: This class is now obsolete.
Contains a cache of XML Schema definition language (XSD) and XML-Data Reduced (XDR) schemas. This class cannot be inherited. Namespace: System.Xml.SchemaAssembly: System.Xml (in system.xml.dll)
'Declaration <ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202")> _ Public NotInheritable Class XmlSchemaCollection Implements ICollection, IEnumerable 'Usage Dim instance As XmlSchemaCollection
/** @attribute ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202") */
public final class XmlSchemaCollection implements ICollection, IEnumerable
ObsoleteAttribute("Use System.Xml.Schema.XmlSchemaSet for schema compilation and validation. http://go.microsoft.com/fwlink/?linkid=14202") public final class XmlSchemaCollection implements ICollection, IEnumerable
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.
Important: |
|---|
| 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.
Imports System Imports System.Xml Imports System.Xml.Schema Imports System.IO public class ValidXSD public shared sub Main() Dim sc as XmlSchemaCollection = new XmlSchemaCollection() AddHandler sc.ValidationEventHandler, AddressOf ValidationCallBack sc.Add(nothing, "books.xsd") if(sc.Count > 0) Dim tr as XmlTextReader = new XmlTextReader("notValidXSD.xml") Dim rdr as XmlValidatingReader = new XmlValidatingReader(tr) rdr.ValidationType = ValidationType.Schema rdr.Schemas.Add(sc) AddHandler rdr.ValidationEventHandler, AddressOf ValidationCallBack while (rdr.Read()) end while end if end sub private shared sub ValidationCallBack(sender as object, e as ValidationEventArgs) Console.WriteLine("XSD Error: {0}", e.Message) end sub end class
import System.*;
import System.Xml.*;
import System.Xml.Schema.*;
import System.IO.*;
public class ValidXSD
{
public static void main(String[] args)
{
XmlSchemaCollection sc = new XmlSchemaCollection();
sc.add_ValidationEventHandler(new ValidationEventHandler(
ValidationCallBack));
sc.Add(null, "books.xsd");
if (sc.get_Count() > 0) {
XmlTextReader tr = new XmlTextReader("notValidXSD.xml");
XmlValidatingReader rdr = new XmlValidatingReader(tr);
rdr.set_ValidationType(ValidationType.Schema);
rdr.get_Schemas().Add(sc);
rdr.add_ValidationEventHandler(new ValidationEventHandler(
ValidationCallBack));
while (rdr.Read()) {
}
}
} //main
private static void ValidationCallBack(Object sender,
ValidationEventArgs e)
{
Console.WriteLine("Validation Error: {0}", e.get_Message());
} //ValidationCallBack
} //ValidXSD
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Important: