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ą.

C#
public class XmlSchemaSimpleType : System.Xml.Schema.XmlSchemaType
Dziedziczenie

Przykłady

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

C#
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);
    }
}

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

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

Produkt Wersje
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1