Export (0) Print
Expand All

XmlSchemaEnumerationFacet Class

Specifies a list of valid values for a simpleType element. Declaration is contained within a restriction declaration. Represents the World Wide Web Consortium (W3C) enumeration facet.

For a list of all members of this type, see XmlSchemaEnumerationFacet Members.

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaAnnotated
         System.Xml.Schema.XmlSchemaFacet
            System.Xml.Schema.XmlSchemaEnumerationFacet

[Visual Basic]
Public Class XmlSchemaEnumerationFacet
   Inherits XmlSchemaFacet
[C#]
public class XmlSchemaEnumerationFacet : XmlSchemaFacet
[C++]
public __gc class XmlSchemaEnumerationFacet : public XmlSchemaFacet
[JScript]
public class XmlSchemaEnumerationFacet extends XmlSchemaFacet

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Example

[Visual Basic, C#, C++] The following example shows the use of the XmlSchemaEnumerationFacet class.

[Visual Basic] 
Option Strict
Option Explicit

Imports System
Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    
    Public Shared Sub Main()
        
        Dim schema As New XmlSchema()
        
        ' <xs:simpleType name="SizeType">
        Dim SizeType As New XmlSchemaSimpleType()
        SizeType.Name = "SizeType"
        
        ' <xs:restriction base="xs:string">
        Dim restriction As New XmlSchemaSimpleTypeRestriction()
        restriction.BaseTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:enumeration value="Small"/>
        Dim enumerationSmall As New XmlSchemaEnumerationFacet()
        enumerationSmall.Value = "Small"
        restriction.Facets.Add(enumerationSmall)
        
        ' <xs:enumeration value="Medium"/>
        Dim enumerationMedium As New XmlSchemaEnumerationFacet()
        enumerationMedium.Value = "Medium"
        restriction.Facets.Add(enumerationMedium)
        
        ' <xs:enumeration value="Large"/>
        Dim enumerationLarge As New XmlSchemaEnumerationFacet()
        enumerationLarge.Value = "Large"
        restriction.Facets.Add(enumerationLarge)
        
        SizeType.Content = restriction
        
        schema.Items.Add(SizeType)
        
        ' <xs:element name="Item">
        Dim elementItem As New XmlSchemaElement()
        elementItem.Name = "Item"
        
        ' <xs:complexType>
        Dim complexType As New XmlSchemaComplexType()
        
        ' <xs:attribute name="Size" type="SizeType"/>
        Dim attributeSize As New XmlSchemaAttribute()
        attributeSize.Name = "Size"
        attributeSize.SchemaTypeName = New XmlQualifiedName("SizeType", "")
        complexType.Attributes.Add(attributeSize)
        
        elementItem.SchemaType = complexType
        
        schema.Items.Add(elementItem)
        
        schema.Compile(AddressOf ValidationCallbackOne)
        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
        schema.Write(Console.Out, nsmgr)
    End Sub 'Main
    
    
    Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub 'ValidationCallbackOne
End Class 'XMLSchemaExamples

[C#] 
using System;
using System.Xml;  
using System.Xml.Schema;

class XMLSchemaExamples {
    public static void Main() {
 
        XmlSchema schema = new XmlSchema();

        // <xs:simpleType name="SizeType">
        XmlSchemaSimpleType SizeType = new XmlSchemaSimpleType();
        SizeType.Name = "SizeType";

        // <xs:restriction base="xs:string">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
        restriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:enumeration value="Small"/>
        XmlSchemaEnumerationFacet enumerationSmall = new XmlSchemaEnumerationFacet();
        enumerationSmall.Value = "Small";
        restriction.Facets.Add(enumerationSmall);

        // <xs:enumeration value="Medium"/>
        XmlSchemaEnumerationFacet enumerationMedium = new XmlSchemaEnumerationFacet();
        enumerationMedium.Value = "Medium";
        restriction.Facets.Add(enumerationMedium);

        // <xs:enumeration value="Large"/>
        XmlSchemaEnumerationFacet enumerationLarge = new XmlSchemaEnumerationFacet();
        enumerationLarge.Value = "Large";
        restriction.Facets.Add(enumerationLarge);

        SizeType.Content = restriction;

        schema.Items.Add(SizeType);

        // <xs:element name="Item">
        XmlSchemaElement elementItem = new XmlSchemaElement();
        elementItem.Name = "Item";
                
        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        // <xs:attribute name="Size" type="SizeType"/>
        XmlSchemaAttribute attributeSize = new XmlSchemaAttribute();
        attributeSize.Name = "Size";
        attributeSize.SchemaTypeName = new XmlQualifiedName("SizeType", "");
        complexType.Attributes.Add(attributeSize);

        elementItem.SchemaType = complexType;
                
        schema.Items.Add(elementItem);

        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {

        Console.WriteLine(args.Message);
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples {
public:
    static void main() {
 
        XmlSchema* schema = new XmlSchema();

        // <xs:simpleType name="SizeType">
        XmlSchemaSimpleType* SizeType = new XmlSchemaSimpleType();
        SizeType->Name = S"SizeType";

        // <xs:restriction base="xs:string">
        XmlSchemaSimpleTypeRestriction* restriction = new XmlSchemaSimpleTypeRestriction();
        restriction->BaseTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");

        // <xs:enumeration value="Small"/>
        XmlSchemaEnumerationFacet* enumerationSmall = new XmlSchemaEnumerationFacet();
        enumerationSmall->Value = S"Small";
        restriction->Facets->Add(enumerationSmall);

        // <xs:enumeration value="Medium"/>
        XmlSchemaEnumerationFacet* enumerationMedium = new XmlSchemaEnumerationFacet();
        enumerationMedium->Value = S"Medium";
        restriction->Facets->Add(enumerationMedium);

        // <xs:enumeration value="Large"/>
        XmlSchemaEnumerationFacet* enumerationLarge = new XmlSchemaEnumerationFacet();
        enumerationLarge->Value = S"Large";
        restriction->Facets->Add(enumerationLarge);

        SizeType->Content = restriction;

        schema->Items->Add(SizeType);

        // <xs:element name="Item">
        XmlSchemaElement* elementItem = new XmlSchemaElement();
        elementItem->Name = S"Item";
                
        // <xs:complexType>
        XmlSchemaComplexType* complexType = new XmlSchemaComplexType();

        // <xs:attribute name="Size" type="SizeType"/>
        XmlSchemaAttribute* attributeSize = new XmlSchemaAttribute();
        attributeSize->Name = S"Size";
        attributeSize->SchemaTypeName = new XmlQualifiedName(S"SizeType", S"");
        complexType->Attributes->Add(attributeSize);

        elementItem->SchemaType = complexType;
                
        schema->Items->Add(elementItem);

        schema->Compile(new ValidationEventHandler(0, ValidationCallbackOne));
     XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr->AddNamespace(S"xs", S"http://www.w3.org/2001/XMLSchema");
        schema->Write(Console::Out,nsmgr);
    }

    static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) {

        Console::WriteLine(args->Message);
    }
};

int main()
{
    XMLSchemaExamples::main();
}

[Visual Basic, C#, C++] The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="SizeType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="Small" />
      <xs:enumeration value="Medium" />
      <xs:enumeration value="Large" />
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="Item">
    <xs:complexType>
      <xs:attribute name="Size" type="SizeType" />
    </xs:complexType>
  </xs:element>
</xs:schema>

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Xml (in System.Xml.dll)

See Also

XmlSchemaEnumerationFacet Members | System.Xml.Schema Namespace

Show:
© 2014 Microsoft