This documentation is archived and is not being maintained.

XmlSchemaDatatype Class

Represents the abstract class for mapping XML Schema definition language (XSD) and .NET Framework types.

For a list of all members of this type, see XmlSchemaDatatype Members.


[Visual Basic]
MustInherit Public Class XmlSchemaDatatype
public abstract class XmlSchemaDatatype
public __gc __abstract class XmlSchemaDatatype
public abstract class XmlSchemaDatatype

Thread Safety

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


[Visual Basic, C#, C++] The following example shows use of the XmlSchemaDatatype class.

[Visual Basic] 
Imports System
Imports System.Xml
Imports System.Xml.Schema


Class XMLSchemaExamples
   Public Shared Sub Main()
      Dim xtr As New XmlTextReader("example.xsd")
      Dim schema As XmlSchema = XmlSchema.Read(xtr, New ValidationEventHandler(AddressOf ValidationCallbackOne))
      schema.Compile(New ValidationEventHandler(AddressOf ValidationCallbackOne))
      Dim schemaObject As XmlSchemaObject
      For Each schemaObject In  schema.Items
         If schemaObject.GetType() Is GetType(XmlSchemaSimpleType) Then
            Dim simpleType As XmlSchemaSimpleType = CType(schemaObject, XmlSchemaSimpleType)
            Console.WriteLine("{0} {1}", simpleType.Name, simpleType.Datatype.ValueType)
         End If
         If schemaObject.GetType() Is GetType(XmlSchemaComplexType) Then
            Dim complexType As XmlSchemaComplexType = CType(schemaObject, XmlSchemaComplexType)
            Console.WriteLine("{0} {1}", complexType.Name, complexType.Datatype.ValueType)
         End If
      Next schemaObject
   End Sub 'Main
   Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs)
   End Sub 'ValidationCallbackOne
End Class 'XMLSchemaExamples

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

class XMLSchemaExamples {
    public static void Main() {
        XmlTextReader xtr = new XmlTextReader("example.xsd");
    XmlSchema schema = XmlSchema.Read(xtr, new ValidationEventHandler(ValidationCallbackOne));

        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
        foreach (XmlSchemaObject schemaObject in schema.Items) {
            if (schemaObject.GetType() == typeof(XmlSchemaSimpleType)) {
                XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) schemaObject;
                Console.WriteLine("{0} {1}", simpleType.Name, simpleType.Datatype.ValueType);
            if (schemaObject.GetType() == typeof(XmlSchemaComplexType)) {
                XmlSchemaComplexType complexType = (XmlSchemaComplexType) schemaObject;
                Console.WriteLine("{0} {1}", complexType.Name, complexType.Datatype.ValueType);

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples {
    static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) {

int main() {
    XmlTextReader* xtr = new XmlTextReader(S"example.xsd");
    XmlSchema* schema = XmlSchema::Read(xtr, 
        new ValidationEventHandler(0, XMLSchemaExamples::ValidationCallbackOne));

    schema->Compile(new ValidationEventHandler(0, XMLSchemaExamples::ValidationCallbackOne));

    Collections::IEnumerator* myEnum = schema->Items->GetEnumerator();
    while (myEnum->MoveNext()) {
        XmlSchemaObject* schemaObject = __try_cast<XmlSchemaObject*>(myEnum->Current);

        if (dynamic_cast<XmlSchemaSimpleType*>(schemaObject)) {
            XmlSchemaSimpleType* simpleType = dynamic_cast<XmlSchemaSimpleType*>(schemaObject);
            Console::WriteLine(S" {0} {1}", simpleType->Name, simpleType->Datatype->ValueType);
        if (dynamic_cast<XmlSchemaComplexType*>(schemaObject)) {
            XmlSchemaComplexType* complexType = dynamic_cast<XmlSchemaComplexType*>(schemaObject);
            Console::WriteLine(S" {0} {1}", complexType->Name, complexType->Datatype->ValueType);

[Visual Basic, C#, C++] The following XML file is used for the preceding code example.

<?xml version="1.0"?>
<xs:schema xmlns:xs="">
    <xs:simpleType name="LotteryNumber">
        <xs:restriction base="xs:int">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="99"/>

[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.


Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

XmlSchemaDatatype Members | System.Xml.Schema Namespace