XmlSchemaInfoType Class
Represents a type in an XML Schema definition (XSD). This class provides information about the data type, derived by, and base types of an XML Schema type.
Namespace
System.Xml.Schema
Assembly
System.Xml.dll
Syntax
public abstract class XmlSchemaInfoType : XmlSchemaObject
Inheritance
System.Object
→ System.Xml.Schema.XmlSchemaObject
→ System.Xml.Schema.XmlSchemaInfoType
Derived Classes
The XmlSchemaInfoType
class is an abstract base class. The following classes derive from it:
XmlSchemaDatatype
XmlSchemaSimpleType
XmlSchemaComplexType
Methods
Name | Description |
---|---|
GetBaseTypes() |
Returns an array of XmlSchemaInfoType objects representing the base types of this type. |
IsDerivedFrom(XmlSchemaInfoType baseType) |
Determines whether this type is derived from the specified base type. |
Properties
Name | Description |
---|---|
DerivedBy |
Gets a value indicating how this type is derived from its base type (e.g., Restriction, List, Union). |
BaseTypes |
Gets the base types of this schema type. |
Datatype |
Gets the underlying XML Schema datatype. |
IsMixed |
Gets a value indicating whether this complex type allows mixed content. |
QualifiedName |
Gets the qualified name of the schema type. |
Remarks
The XmlSchemaInfoType
class is fundamental for understanding the structure and relationships
between different types within an XML Schema. It allows developers to programmatically inspect and
validate XML documents against an XSD. The abstract nature of this class means you will typically
work with its concrete derived classes like XmlSchemaSimpleType
and XmlSchemaComplexType
.
Example
The following example demonstrates how to create a simple type and then retrieve information about it.
using System;
using System.Xml.Schema;
public class Example
{
public static void Main(string[] args)
{
// Create a simple schema
XmlSchema schema = new XmlSchema();
// Create a simple type definition for string
XmlSchemaSimpleType stringType = new XmlSchemaSimpleType();
stringType.Name = "MyStringType";
stringType.Content = new XmlSchemaSimpleTypeRestriction();
((XmlSchemaSimpleTypeRestriction)stringType.Content).BaseTypeName = new System.Xml.XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
schema.Items.Add(stringType);
// Now, let's get information about this type
XmlSchemaObjectTable types = schema.SchemaTypes;
XmlSchemaInfoType retrievedType = (XmlSchemaInfoType)types["MyStringType", schema.TargetNamespace];
if (retrievedType != null)
{
Console.WriteLine($"Type Name: {retrievedType.QualifiedName}");
Console.WriteLine($"Base Type: {retrievedType.Datatype.ValueType.Name}");
Console.WriteLine($"Derived By: {retrievedType.DerivedBy}");
}
}
}