XmlSchemaSimpleType Třída
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
simpleType Představuje prvek pro jednoduchý obsah ze schématu XML určený konsorciem W3C (World Wide Web Consortium). Tato třída definuje jednoduchý typ. Jednoduché typy mohou 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;
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ých typů (předdefinovaných datových typů a odvozených jednoduchých typů). Jednoduchý typ nemůže obsahovat elementy a nemůže mít atributy.
Konstruktory
| Name | Description |
|---|---|
| XmlSchemaSimpleType() |
Inicializuje novou instanci XmlSchemaSimpleType třídy. |
Vlastnosti
| Name | Description |
|---|---|
| Annotation |
Získá nebo nastaví |
| BaseSchemaType |
Zastaralé.
Zastaralé.
Zastaralé.
Získá post-kompilace typ objektu nebo integrovaný XML Schema Definition Language (XSD) datový typ, simpleType element nebo complexType element. Toto je 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í jeden z XmlSchemaSimpleTypeUnion, XmlSchemaSimpleTypeListnebo XmlSchemaSimpleTypeRestriction. |
| Datatype |
Získá hodnotu po kompilaci pro datový typ komplexního typu. (Zděděno od XmlSchemaType) |
| DerivedBy |
Získá post-kompilace 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í, zda tento typ má 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ý |
| LinePosition |
Získá nebo nastaví pozici řádku v souboru, na který |
| 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 |
| 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
| Name | Description |
|---|---|
| Equals(Object) |
Určuje, zda je zadaný objekt roven aktuálnímu objektu. (Zděděno od Object) |
| GetHashCode() |
Slouží jako výchozí funkce hash. (Zděděno od Object) |
| GetType() |
Získá Type aktuální instance. (Zděděno od Object) |
| MemberwiseClone() |
Vytvoří mělkou kopii aktuálního Object. (Zděděno od Object) |
| ToString() |
Vrátí řetězec, který představuje aktuální objekt. (Zděděno od Object) |