public class XmlSchemaSimpleType : XmlSchemaType
|
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples {
public static void Main() {
XmlSchema schema = new XmlSchema();
// <xs:simpleType name="LotteryNumber">
XmlSchemaSimpleType LotteryNumberType = new XmlSchemaSimpleType();
LotteryNumberType.Name = "LotteryNumber";
// <xs:restriction base="xs:int">
XmlSchemaSimpleTypeRestriction LotteryNumberRestriction = new XmlSchemaSimpleTypeRestriction();
LotteryNumberRestriction.BaseTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");
// <xs:minInclusive value="1"/>
XmlSchemaMinInclusiveFacet minInclusive = new XmlSchemaMinInclusiveFacet();
minInclusive.Value = "1";
LotteryNumberRestriction.Facets.Add(minInclusive);
// <xs:maxInclusive value="99"/>
XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
maxInclusive.Value = "99";
LotteryNumberRestriction.Facets.Add(maxInclusive);
LotteryNumberType.Content = LotteryNumberRestriction;
schema.Items.Add(LotteryNumberType);
// <xs:simpleType name="LotteryNumberList">
XmlSchemaSimpleType LotteryNumberListType = new XmlSchemaSimpleType();
LotteryNumberListType.Name = "LotteryNumberList";
// <xs:list itemType="LotteryNumber"/>
XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
list.ItemTypeName = new XmlQualifiedName("LotteryNumber", "");
LotteryNumberListType.Content = list;
schema.Items.Add(LotteryNumberListType);
// <xs:simpleType name="LotteryNumbers">
XmlSchemaSimpleType LotteryNumbersType = new XmlSchemaSimpleType();
LotteryNumbersType.Name = "LotteryNumbers";
// <xs:restriction base="LotteryNumberList">
XmlSchemaSimpleTypeRestriction LotteryNumbersRestriction = new XmlSchemaSimpleTypeRestriction();
LotteryNumbersRestriction.BaseTypeName = new XmlQualifiedName("LotteryNumberList", "");
// <xs:length value="5"/>
XmlSchemaLengthFacet length = new XmlSchemaLengthFacet();
length.Value = "5";
LotteryNumbersRestriction.Facets.Add(length);
LotteryNumbersType.Content = LotteryNumbersRestriction;
schema.Items.Add(LotteryNumbersType);
// <xs:element name="TodaysLottery" type="LotteryNumbers">
XmlSchemaElement TodaysLottery = new XmlSchemaElement();
TodaysLottery.Name = "TodaysLottery";
TodaysLottery.SchemaTypeName = new XmlQualifiedName("LotteryNumbers", "");
schema.Items.Add(TodaysLottery);
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
schema.Write(Console.Out, nsmgr);
}
public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {
Console.WriteLine(args.Message);
}
}
The following XML file is generated for the preceding code example.
<?xml version="1.0" encoding="IBM437"?>
<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:simpleType name="LotteryNumberList">
<xs:list itemType="LotteryNumber"/>
</xs:simpleType>
<xs:simpleType name="LotteryNumbers">
<xs:restriction base="LotteryNumberList">
<xs:length value="5"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="TodaysLottery" type="LotteryNumbers">
</xs:element>
</xs:schema>
| ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
| Annotation (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation Gets or sets the annotation property. |
| BaseSchemaType (inherited from System.Xml.Schema.XmlSchemaType) |
Read-only See base class member description: System.Xml.Schema.XmlSchemaType.BaseSchemaType Gets the object of the simpleType element or complexType element. This is a post-schema-validation-infoset variable. |
| Content | Read-write Gets or sets one of XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeList, or XmlSchemaSimpleTypeRestriction. |
| Datatype (inherited from System.Xml.Schema.XmlSchemaType) |
Read-only See base class member description: System.Xml.Schema.XmlSchemaType.Datatype Gets the data type that holds the post-compilation value. |
| DerivedBy (inherited from System.Xml.Schema.XmlSchemaType) |
Read-only See base class member description: System.Xml.Schema.XmlSchemaType.DerivedBy When overridden in a derived class, this property gets information that indicates how this element has been derived from a base type. This property holds the post-compilation value. |
| Final (inherited from System.Xml.Schema.XmlSchemaType) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaType.Final Gets or sets the final property to indicate that no further derivations are allowed. |
| FinalResolved (inherited from System.Xml.Schema.XmlSchemaType) |
Read-only See base class member description: System.Xml.Schema.XmlSchemaType.FinalResolved Gets the post-compilation value of the Final property that holds the post-compilation value of the Final property. |
| Id (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id Gets or sets the string id. |
| IsMixed (inherited from System.Xml.Schema.XmlSchemaType) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaType.IsMixed Indicates that this type has a mixed content model. This property is only valid in a complex type. |
| LineNumber (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber Gets or sets the line number in the file to which the schema element refers. |
| LinePosition (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition Gets or sets the line position in the file to which the schema element refers. |
| Name (inherited from System.Xml.Schema.XmlSchemaType) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaType.Name Gets or sets the name of the type. |
| Namespaces (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces |
| QualifiedName (inherited from System.Xml.Schema.XmlSchemaType) |
Read-only See base class member description: System.Xml.Schema.XmlSchemaType.QualifiedName Gets the qualified name for the type built from the Name attribute of this type. This holds the post-compilation value. |
| SourceUri (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri Gets or sets the source location for the file that loaded the schema. |
| UnhandledAttributes (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes Gets or sets the qualified attributes that do not belong to the schema target namespace. |
| Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
| GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
| GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
| ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
| Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
| MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public XmlSchemaSimpleType(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public object BaseSchemaType {get;}
|
public XmlSchemaSimpleTypeContent Content {get; set;}
|
| Simple type | Description |
|---|---|
| Restriction | Restricts the range of values for the simple type to a subset of those for the inherited simple type. |
| List | Defines a simple type that contains a white space-separated list of values of an inherited simple type. |
| Union | Defines a simple type that contains a union of the values of two or more inherited simple types. |
public XmlSchemaDatatype Datatype {get;}
|
public XmlSchemaDerivationMethod DerivedBy {get;}
|
| Enum | Description |
|---|---|
| None | No derivation method specified. |
| Substitution | Derived by Substitution. |
| Extension | Derived by Extension. |
| Restriction | Derived by Restriction. |
| List | Derived by List. |
| Union | Derived by Union. |
public XmlSchemaDerivationMethod Final {get; set;}
|
| Enum | Description |
|---|---|
| Empty | Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place. |
| None | No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting. |
| Substitution | Cannot be replaced by a type derived by Substitution. |
| Extension | Cannot be replaced by a type derived by Extension. |
| Restriction | Cannot be replaced by a type derived by Restriction. |
| All | #all . Cannot be replaced by a type derived by any derivation method. |
The following table shows the values that this property can contain for complex type.
| Enum | Description |
|---|---|
| Empty | Overrides the schema blockDefault setting allowing any derivations, by restriction, extension, or substitution to take place. |
| None | No derivation method is specified. This is the default. Derivation rules are taken from the schema blockDefault setting. |
| Substitution | Cannot be replaced by a type derived by Substitution. |
| Extension | Cannot be replaced by a type derived by Extension. |
| Restriction | Cannot be replaced by a type derived by Restriction. |
| All | #all . Cannot be replaced by a type derived by any derivation method. |
public XmlSchemaDerivationMethod FinalResolved {get;}
|
public string Id {get; set;}
|
Optional.
public virtual bool IsMixed {get; set;}
|
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public string Name {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlQualifiedName QualifiedName {get;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaSimpleType(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |