XmlSchemaSimpleType Třída

Definice

simpleType Představuje prvek pro jednoduchý obsah ze schématu XML, jak je určeno World Wide Web Consortium (W3C). Tato třída definuje jednoduchý typ. Jednoduché typy můžou zadat informace a omezení pro hodnotu atributů nebo prvků s obsahem jen pro text.

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
Dědičnost

Příklady

Následující příklad ukazuje použití XmlSchemaSimpleType třídy.

#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

Následující soubor XML se vygeneruje pro předchozí příklad kódu.

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

Poznámky

Jednoduché typy jsou definovány odvozením z existujících jednoduché typů (předdefinované datové typy a jednoduché odvozené typy). Jednoduchý typ nemůže obsahovat elementy a nemůže mít atributy.

Konstruktory

XmlSchemaSimpleType()

Inicializuje novou instanci XmlSchemaSimpleType třídy.

Vlastnosti

Annotation

Získá nebo nastaví annotation vlastnost.

(Zděděno od XmlSchemaAnnotated)
BaseSchemaType
Zastaralé.
Zastaralé.
Zastaralé.

Získá typ objektu post-kompilace nebo integrovaný datový typ XML Schema Definition Language (XSD), simpleType element nebo complexType element. Jedná se o vlastnost infoset po kompilaci schématu.

(Zděděno od XmlSchemaType)
BaseXmlSchemaType

Získá hodnotu po kompilaci pro základní typ tohoto typu schématu.

(Zděděno od XmlSchemaType)
Content

Získá nebo nastaví jednu z XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeListnebo XmlSchemaSimpleTypeRestriction.

Datatype

Získá hodnotu po kompilaci pro datový typ komplexního typu.

(Zděděno od XmlSchemaType)
DerivedBy

Získá pokompilační informace o tom, jak byl tento prvek odvozen z jeho základního typu.

(Zděděno od XmlSchemaType)
Final

Získá nebo nastaví konečný atribut odvození typu, který označuje, zda jsou další odvození povoleny.

(Zděděno od XmlSchemaType)
FinalResolved

Získá hodnotu Final po kompilaci vlastnosti.

(Zděděno od XmlSchemaType)
Id

Získá nebo nastaví ID řetězce.

(Zděděno od XmlSchemaAnnotated)
IsMixed

Získá nebo nastaví hodnotu označující, jestli má tento typ smíšený model obsahu. Tato vlastnost je platná pouze v komplexním typu.

(Zděděno od XmlSchemaType)
LineNumber

Získá nebo nastaví číslo řádku v souboru, na který schema prvek odkazuje.

(Zděděno od XmlSchemaObject)
LinePosition

Získá nebo nastaví pozici čáry v souboru, na který schema prvek odkazuje.

(Zděděno od XmlSchemaObject)
Name

Získá nebo nastaví název typu.

(Zděděno od XmlSchemaType)
Namespaces

Získá nebo nastaví XmlSerializerNamespaces použití s tímto objektem schématu.

(Zděděno od XmlSchemaObject)
Parent

Získá nebo nastaví nadřazený objekt tohoto XmlSchemaObject.

(Zděděno od XmlSchemaObject)
QualifiedName

Získá kvalifikovaný název pro typ sestavený z atributu Name tohoto typu. Jedná se o vlastnost po kompilaci schématu.

(Zděděno od XmlSchemaType)
SourceUri

Získá nebo nastaví zdrojové umístění pro soubor, který načetl schéma.

(Zděděno od XmlSchemaObject)
TypeCode

XmlTypeCode Získá typ.

(Zděděno od XmlSchemaType)
UnhandledAttributes

Získá nebo nastaví kvalifikované atributy, které nepatří do cílového oboru názvů aktuálního schématu.

(Zděděno od XmlSchemaAnnotated)

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro