XmlSchemaSimpleType Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rappresenta l'elemento simpleType per contenuto semplice da XML Schema, come specificato dal World Wide Web Consortium (W3C). Questa classe definisce un tipo semplice. I tipi semplici possono specificare informazioni e vincoli per il valore di attributi o elementi con contenuto solo testo.
public ref class XmlSchemaSimpleType : System::Xml::Schema::XmlSchemaType
public class XmlSchemaSimpleType : System.Xml.Schema.XmlSchemaType
type XmlSchemaSimpleType = class
inherit XmlSchemaType
Public Class XmlSchemaSimpleType
Inherits XmlSchemaType
- Ereditarietà
Esempio
Nell'esempio seguente viene illustrato l'uso della XmlSchemaSimpleType classe .
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);
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
schemaSet.Add(schema);
schemaSet.Compile();
XmlSchema compiledSchema = null;
foreach (XmlSchema schema1 in schemaSet.Schemas())
{
compiledSchema = schema1;
}
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
compiledSchema.Write(Console.Out, nsmgr);
}
public static void ValidationCallbackOne(object sender, ValidationEventArgs args)
{
Console.WriteLine(args.Message);
}
}
Option Strict On
Option Explicit On
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema As New XmlSchema()
' <xs:simpleType name="LotteryNumber">
Dim LotteryNumberType As New XmlSchemaSimpleType()
LotteryNumberType.Name = "LotteryNumber"
' <xs:restriction base="xs:int">
Dim LotteryNumberRestriction As New XmlSchemaSimpleTypeRestriction()
LotteryNumberRestriction.BaseTypeName = New XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema")
' <xs:minInclusive value="1"/>
Dim minInclusive As New XmlSchemaMinInclusiveFacet()
minInclusive.Value = "1"
LotteryNumberRestriction.Facets.Add(minInclusive)
' <xs:maxInclusive value="99"/>
Dim maxInclusive As New XmlSchemaMaxInclusiveFacet()
maxInclusive.Value = "99"
LotteryNumberRestriction.Facets.Add(maxInclusive)
LotteryNumberType.Content = LotteryNumberRestriction
schema.Items.Add(LotteryNumberType)
' <xs:simpleType name="LotteryNumberList">
Dim LotteryNumberListType As New XmlSchemaSimpleType()
LotteryNumberListType.Name = "LotteryNumberList"
' <xs:list itemType="LotteryNumber"/>
Dim list As New XmlSchemaSimpleTypeList()
list.ItemTypeName = New XmlQualifiedName("LotteryNumber", "")
LotteryNumberListType.Content = list
schema.Items.Add(LotteryNumberListType)
' <xs:simpleType name="LotteryNumbers">
Dim LotteryNumbersType As New XmlSchemaSimpleType()
LotteryNumbersType.Name = "LotteryNumbers"
' <xs:restriction base="LotteryNumberList">
Dim LotteryNumbersRestriction As New XmlSchemaSimpleTypeRestriction()
LotteryNumbersRestriction.BaseTypeName = New XmlQualifiedName("LotteryNumberList", "")
' <xs:length value="5"/>
Dim length As New XmlSchemaLengthFacet()
length.Value = "5"
LotteryNumbersRestriction.Facets.Add(length)
LotteryNumbersType.Content = LotteryNumbersRestriction
schema.Items.Add(LotteryNumbersType)
' <xs:element name="TodaysLottery" type="LotteryNumbers">
Dim TodaysLottery As New XmlSchemaElement()
TodaysLottery.Name = "TodaysLottery"
TodaysLottery.SchemaTypeName = New XmlQualifiedName("LotteryNumbers", "")
schema.Items.Add(TodaysLottery)
Dim schemaSet As New XmlSchemaSet()
AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne
schemaSet.Add(schema)
schemaSet.Compile()
Dim compiledSchema As XmlSchema = Nothing
For Each schema1 As XmlSchema In schemaSet.Schemas()
compiledSchema = schema1
Next
Dim nsmgr As New XmlNamespaceManager(New NameTable())
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
compiledSchema.Write(Console.Out, nsmgr)
End Sub
Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub
End Class
Il file XML seguente viene generato per l'esempio di codice precedente.
<?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>
Commenti
I tipi semplici vengono definiti derivandoli da tipi semplici esistenti (tipi di dati predefiniti e tipi semplici derivati). Un tipo semplice non può contenere elementi e non può avere attributi.
Costruttori
| Nome | Descrizione |
|---|---|
| XmlSchemaSimpleType() |
Inizializza una nuova istanza della classe XmlSchemaSimpleType. |
Proprietà
| Nome | Descrizione |
|---|---|
| Annotation |
Ottiene o imposta la |
| BaseSchemaType |
Obsoleti.
Obsoleti.
Obsoleti.
Ottiene il tipo di oggetto post-compilazione o il tipo di dati XSD (XML Schema Definition Language) predefinito, l'elemento simpleType o l'elemento complexType. Si tratta di una proprietà infoset post-schema-compilazione. (Ereditato da XmlSchemaType) |
| BaseXmlSchemaType |
Ottiene il valore di post-compilazione per il tipo di base di questo tipo di schema. (Ereditato da XmlSchemaType) |
| Content |
Ottiene o imposta uno di XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeListo XmlSchemaSimpleTypeRestriction. |
| Datatype |
Ottiene il valore di post-compilazione per il tipo di dati del tipo complesso. (Ereditato da XmlSchemaType) |
| DerivedBy |
Ottiene le informazioni di post-compilazione sul modo in cui questo elemento è stato derivato dal tipo di base. (Ereditato da XmlSchemaType) |
| Final |
Ottiene o imposta l'attributo finale della derivazione del tipo che indica se sono consentite altre derivazioni. (Ereditato da XmlSchemaType) |
| FinalResolved |
Ottiene il valore di post-compilazione della Final proprietà . (Ereditato da XmlSchemaType) |
| Id |
Ottiene o imposta l'ID stringa. (Ereditato da XmlSchemaAnnotated) |
| IsMixed |
Ottiene o imposta un valore che indica se questo tipo ha un modello di contenuto misto. Questa proprietà è valida solo in un tipo complesso. (Ereditato da XmlSchemaType) |
| LineNumber |
Ottiene o imposta il numero di riga nel file a cui fa riferimento l'elemento |
| LinePosition |
Ottiene o imposta la posizione della riga nel file a cui fa riferimento l'elemento |
| Name |
Ottiene o imposta il nome del tipo. (Ereditato da XmlSchemaType) |
| Namespaces |
Ottiene o imposta l'oggetto XmlSerializerNamespaces da utilizzare con questo oggetto schema. (Ereditato da XmlSchemaObject) |
| Parent |
Ottiene o imposta l'elemento padre dell'oggetto XmlSchemaObject. (Ereditato da XmlSchemaObject) |
| QualifiedName |
Ottiene il nome completo per il tipo compilato dall'attributo |
| SourceUri |
Ottiene o imposta il percorso di origine per il file che ha caricato lo schema. (Ereditato da XmlSchemaObject) |
| TypeCode |
Ottiene l'oggetto XmlTypeCode del tipo. (Ereditato da XmlSchemaType) |
| UnhandledAttributes |
Ottiene o imposta gli attributi qualificati che non appartengono allo spazio dei nomi di destinazione dello schema corrente. (Ereditato da XmlSchemaAnnotated) |
Metodi
| Nome | Descrizione |
|---|---|
| Equals(Object) |
Determina se l'oggetto specificato è uguale all'oggetto corrente. (Ereditato da Object) |
| GetHashCode() |
Funge da funzione hash predefinita. (Ereditato da Object) |
| GetType() |
Ottiene il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |