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.
System.Object
System.Xml.Schema.XmlSchemaDatatype
[Visual Basic] MustInherit Public Class XmlSchemaDatatype [C#] public abstract class XmlSchemaDatatype [C++] public __gc __abstract class XmlSchemaDatatype [JScript] 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.
Example
[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 xtr.Close() End Sub 'Main Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples [C#] 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); } } xtr.Close(); } public static void ValidationCallbackOne(object sender, ValidationEventArgs args) { Console.WriteLine(args.Message); } } [C++] #using <mscorlib.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; __gc class XMLSchemaExamples { public: static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) { Console::WriteLine(args->Message); } }; 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); } } xtr->Close(); }
[Visual Basic, C#, C++] The following XML file is used for the preceding code example.
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="LotteryNumber">
<xs:restriction base="xs:int">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="99"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
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)