XmlSchemaSimpleType Klasa

Definicja

simpleType Reprezentuje element dla prostej zawartości ze schematu XML określonego przez World Wide Web Consortium (W3C). Ta klasa definiuje prosty typ. Proste typy mogą określać informacje i ograniczenia dla wartości atrybutów lub elementów z zawartością tylko tekstową.

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
Dziedziczenie

Przykłady

W poniższym przykładzie pokazano użycie XmlSchemaSimpleType klasy.

#using <System.Xml.dll>

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

ref class XMLSchemaExamples
{
private:
    static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)
    {
        Console::WriteLine(args->Message);
    }

public:
    static void Main()
    {
        XmlSchema^ schema = gcnew XmlSchema();

        // <xs:simpleType name="LotteryNumber">
        XmlSchemaSimpleType^ LotteryNumberType = gcnew XmlSchemaSimpleType();
        LotteryNumberType->Name = "LotteryNumber";

        // <xs:restriction base="xs:int">
        XmlSchemaSimpleTypeRestriction^ LotteryNumberRestriction = gcnew XmlSchemaSimpleTypeRestriction();
        LotteryNumberRestriction->BaseTypeName = gcnew XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema");

        // <xs:minInclusive value="1"/>
        XmlSchemaMinInclusiveFacet^ minInclusive = gcnew XmlSchemaMinInclusiveFacet();
        minInclusive->Value = "1";
        LotteryNumberRestriction->Facets->Add(minInclusive);

        // <xs:maxInclusive value="99"/>
        XmlSchemaMaxInclusiveFacet^ maxInclusive = gcnew XmlSchemaMaxInclusiveFacet();
        maxInclusive->Value = "99";
        LotteryNumberRestriction->Facets->Add(maxInclusive);

        LotteryNumberType->Content = LotteryNumberRestriction;
        schema->Items->Add(LotteryNumberType);

        // <xs:simpleType name="LotteryNumberList">
        XmlSchemaSimpleType^ LotteryNumberListType = gcnew XmlSchemaSimpleType();
        LotteryNumberListType->Name = "LotteryNumberList";

        // <xs:list itemType="LotteryNumber"/>
        XmlSchemaSimpleTypeList^ list = gcnew XmlSchemaSimpleTypeList();
        list->ItemTypeName = gcnew XmlQualifiedName("LotteryNumber", "");
        LotteryNumberListType->Content = list;

        schema->Items->Add(LotteryNumberListType);

        // <xs:simpleType name="LotteryNumbers">
        XmlSchemaSimpleType^ LotteryNumbersType = gcnew XmlSchemaSimpleType();
        LotteryNumbersType->Name = "LotteryNumbers";

        // <xs:restriction base="LotteryNumberList">
        XmlSchemaSimpleTypeRestriction^ LotteryNumbersRestriction = gcnew XmlSchemaSimpleTypeRestriction();
        LotteryNumbersRestriction->BaseTypeName = gcnew XmlQualifiedName("LotteryNumberList", "");

        // <xs:length value="5"/>
        XmlSchemaLengthFacet^ length = gcnew XmlSchemaLengthFacet();
        length->Value = "5";
        LotteryNumbersRestriction->Facets->Add(length);

        LotteryNumbersType->Content = LotteryNumbersRestriction;

        schema->Items->Add(LotteryNumbersType);

        // <xs:element name="TodaysLottery" type="LotteryNumbers">
        XmlSchemaElement^ TodaysLottery = gcnew XmlSchemaElement();
        TodaysLottery->Name = "TodaysLottery";
        TodaysLottery->SchemaTypeName = gcnew XmlQualifiedName("LotteryNumbers", "");

        schema->Items->Add(TodaysLottery);

        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);
        schemaSet->Add(schema);
        schemaSet->Compile();

        XmlSchema^ compiledSchema = nullptr;

        for each (XmlSchema^ schema1 in schemaSet->Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable());
        nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema->Write(Console::Out, nsmgr);
    }
};

int main()
{
    XMLSchemaExamples::Main();
    return 0;
}
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

Poniższy plik XML jest generowany dla poprzedniego przykładu kodu.

<?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>

Uwagi

Typy proste są definiowane przez wyprowadzanie ich z istniejących typów prostych (wbudowanych typów danych i pochodnych typów prostych). Prosty typ nie może zawierać elementów i nie może mieć atrybutów.

Konstruktory

XmlSchemaSimpleType()

Inicjuje nowe wystąpienie klasy XmlSchemaSimpleType.

Właściwości

Annotation

Pobiera lub ustawia annotation właściwość.

(Odziedziczone po XmlSchemaAnnotated)
BaseSchemaType
Nieaktualne.
Nieaktualne.
Nieaktualne.

Pobiera typ obiektu po kompilacji lub wbudowany typ danych języka definicji schematu XML (XSD), element simpleType lub element complexType. Jest to właściwość infoset kompilacji po schemacie.

(Odziedziczone po XmlSchemaType)
BaseXmlSchemaType

Pobiera wartość po kompilacji dla podstawowego typu tego typu schematu.

(Odziedziczone po XmlSchemaType)
Content

Pobiera lub ustawia jeden z XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeListlub XmlSchemaSimpleTypeRestriction.

Datatype

Pobiera wartość po kompilacji dla typu danych typu złożonego.

(Odziedziczone po XmlSchemaType)
DerivedBy

Pobiera informacje po kompilacji dotyczące sposobu, w jaki ten element został uzyskany z jego typu podstawowego.

(Odziedziczone po XmlSchemaType)
Final

Pobiera lub ustawia ostateczny atrybut wyprowadzania typu, który wskazuje, czy dozwolone są dalsze wyprowadzenia.

(Odziedziczone po XmlSchemaType)
FinalResolved

Pobiera wartość Final po kompilacji właściwości.

(Odziedziczone po XmlSchemaType)
Id

Pobiera lub ustawia identyfikator ciągu.

(Odziedziczone po XmlSchemaAnnotated)
IsMixed

Pobiera lub ustawia wartość wskazującą, czy ten typ ma model zawartości mieszanej. Ta właściwość jest prawidłowa tylko w typie złożonym.

(Odziedziczone po XmlSchemaType)
LineNumber

Pobiera lub ustawia numer wiersza w pliku, do którego schema odwołuje się element.

(Odziedziczone po XmlSchemaObject)
LinePosition

Pobiera lub ustawia położenie wiersza w pliku, do którego schema odwołuje się element.

(Odziedziczone po XmlSchemaObject)
Name

Pobiera lub ustawia nazwę typu.

(Odziedziczone po XmlSchemaType)
Namespaces

Pobiera lub ustawia XmlSerializerNamespaces obiekt do użycia z tym obiektem schematu.

(Odziedziczone po XmlSchemaObject)
Parent

Pobiera lub ustawia element nadrzędny tego XmlSchemaObjectobiektu .

(Odziedziczone po XmlSchemaObject)
QualifiedName

Pobiera kwalifikowaną nazwę typu utworzonego Name z atrybutu tego typu. Jest to właściwość po kompilacji schematu.

(Odziedziczone po XmlSchemaType)
SourceUri

Pobiera lub ustawia lokalizację źródłową pliku, który załadował schemat.

(Odziedziczone po XmlSchemaObject)
TypeCode

XmlTypeCode Pobiera typ .

(Odziedziczone po XmlSchemaType)
UnhandledAttributes

Pobiera lub ustawia kwalifikowane atrybuty, które nie należą do docelowej przestrzeni nazw bieżącego schematu.

(Odziedziczone po XmlSchemaAnnotated)

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy