Share via


XML スキーマの作成

System.Xml.Schema 名前空間のクラスは、W3C (World Wide Web Consortium) 勧告『XML Schema』で定義された構造に割り当てられ、メモリ内に XML スキーマを作成する場合に使用できます。

XML スキーマの作成

以下のコード サンプルでは、SOM API を使用してカスタム XML スキーマをメモリ内に作成します。

要素と属性の作成

このコード サンプルでは、カスタム スキーマを最初から作成するため、子要素、属性、およびそれらに対応する型を作成した後で最上位要素を作成します。

以下のコード サンプルでは、SOM の FirstName クラスおよび LastName クラスを使用して、カスタム スキーマの CustomerId 属性に加え、XmlSchemaElement 要素および XmlSchemaAttribute 要素を作成します。 XML スキーマの Name 要素および XmlSchemaElement 要素の name 属性に対応する XmlSchemaAttribute クラスおよび <xs:element /> クラスの <xs:attribute /> プロパティを除いて、このスキーマで使用できる他のすべての属性 (defaultValuefixedValueform など) には、XmlSchemaElement クラスおよび XmlSchemaAttribute クラスに対応するプロパティが存在します。

// Create the FirstName and LastName elements.
XmlSchemaElement^ firstNameElement = gcnew XmlSchemaElement();
firstNameElement->Name = "FirstName";
XmlSchemaElement^ lastNameElement = gcnew XmlSchemaElement();
lastNameElement->Name = "LastName";

// Create CustomerId attribute.
XmlSchemaAttribute^ idAttribute = gcnew XmlSchemaAttribute();
idAttribute->Name = "CustomerId";
idAttribute->Use = XmlSchemaUse::Required;
// Create the FirstName and LastName elements.
XmlSchemaElement firstNameElement = new XmlSchemaElement();
firstNameElement.Name = "FirstName";
XmlSchemaElement lastNameElement = new XmlSchemaElement();
lastNameElement.Name = "LastName";

// Create CustomerId attribute.
XmlSchemaAttribute idAttribute = new XmlSchemaAttribute();
idAttribute.Name = "CustomerId";
idAttribute.Use = XmlSchemaUse.Required;
' Create the FirstName and LastName elements.
Dim firstNameElement As XmlSchemaElement = New XmlSchemaElement()
firstNameElement.Name = "FirstName"
Dim lastNameElement As XmlSchemaElement = New XmlSchemaElement()
lastNameElement.Name = "LastName"

' Create CustomerId attribute.
Dim idAttribute As XmlSchemaAttribute = New XmlSchemaAttribute()
idAttribute.Name = "CustomerId"
idAttribute.Use = XmlSchemaUse.Required

スキーマの型の作成

要素および属性のコンテンツは、その型によって定義されます。 組み込みのスキーマの型を持つ要素と属性を作成するには、SchemaTypeName クラスを使用する組み込みの修飾名を使用して、XmlSchemaElement クラスまたは XmlSchemaAttribute クラスの XmlQualifiedName プロパティを設定します。 要素と属性のユーザー定義型を作成するには、XmlSchemaSimpleType または XmlSchemaComplexType クラスを使用して単純型または複合型を新しく作成します。

Note

要素または属性の匿名の子である名前のない単純型または複合型 (属性に適用されるのは単純型のみ) を作成するには、SchemaType クラスまたは XmlSchemaElement クラスの XmlSchemaAttribute プロパティではなく、SchemaTypeName クラスまたは XmlSchemaElement クラスの XmlSchemaAttribute プロパティを設定します。

XML スキーマを使用すると、匿名の単純型と名前付きの単純型の両方を、他の単純型 (組み込み型またはユーザー定義型) から制限付きで派生させるか、または、他の単純型のリストまたは和集合として作成することができます。 XmlSchemaSimpleTypeRestriction クラスを使用して単純型を作成する場合には、組み込みの xs:string 型を制限します。 また、XmlSchemaSimpleTypeList または XmlSchemaSimpleTypeUnion クラスを使用すると、リストまたは和集合の型を作成できます。 XmlSchemaSimpleType.Content プロパティは、単純型の制限、リスト、または和集合を表します。

以下のコード サンプルでは、FirstName 要素の型は組み込み型の xs:stringLastName 要素の型は組み込み型 xs:string の制限となる名前付き単純型 (MaxLength ファセット値 20)、CustomerId 属性の型は組み込み型 xs:positiveInteger です。 Customer 要素は匿名の複合型で、そのパーティクルは FirstName 要素および LastName 要素のシーケンスとなり、その属性には CustomerId 属性が含まれます。

Note

また、複合型のパーティクルとして XmlSchemaChoice クラスまたは XmlSchemaAll クラスを使用して、<xs:choice /> または <xs:all /> セマンティクスをレプリケートすることもできます。

// Create the simple type for the LastName element.
XmlSchemaSimpleType^ lastNameType = gcnew XmlSchemaSimpleType();
lastNameType->Name = "LastNameType";
XmlSchemaSimpleTypeRestriction^ lastNameRestriction =
    gcnew XmlSchemaSimpleTypeRestriction();
lastNameRestriction->BaseTypeName =
    gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
XmlSchemaMaxLengthFacet^ maxLength = gcnew XmlSchemaMaxLengthFacet();
maxLength->Value = "20";
lastNameRestriction->Facets->Add(maxLength);
lastNameType->Content = lastNameRestriction;

// Associate the elements and attributes with their types.
// Built-in type.
firstNameElement->SchemaTypeName =
    gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// User-defined type.
lastNameElement->SchemaTypeName =
    gcnew XmlQualifiedName("LastNameType", "http://www.tempuri.org");
// Built-in type.
idAttribute->SchemaTypeName = gcnew XmlQualifiedName("positiveInteger",
    "http://www.w3.org/2001/XMLSchema");

// Create the top-level Customer element.
XmlSchemaElement^ customerElement = gcnew XmlSchemaElement();
customerElement->Name = "Customer";

// Create an anonymous complex type for the Customer element.
XmlSchemaComplexType^ customerType = gcnew XmlSchemaComplexType();
XmlSchemaSequence^ sequence = gcnew XmlSchemaSequence();
sequence->Items->Add(firstNameElement);
sequence->Items->Add(lastNameElement);
customerType->Particle = sequence;

// Add the CustomerId attribute to the complex type.
customerType->Attributes->Add(idAttribute);

// Set the SchemaType of the Customer element to
// the anonymous complex type created above.
customerElement->SchemaType = customerType;
// Create the simple type for the LastName element.
XmlSchemaSimpleType lastNameType = new XmlSchemaSimpleType();
lastNameType.Name = "LastNameType";
XmlSchemaSimpleTypeRestriction lastNameRestriction =
    new XmlSchemaSimpleTypeRestriction();
lastNameRestriction.BaseTypeName =
    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
XmlSchemaMaxLengthFacet maxLength = new XmlSchemaMaxLengthFacet();
maxLength.Value = "20";
lastNameRestriction.Facets.Add(maxLength);
lastNameType.Content = lastNameRestriction;

// Associate the elements and attributes with their types.
// Built-in type.
firstNameElement.SchemaTypeName =
    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// User-defined type.
lastNameElement.SchemaTypeName =
    new XmlQualifiedName("LastNameType", "http://www.tempuri.org");
// Built-in type.
idAttribute.SchemaTypeName = new XmlQualifiedName("positiveInteger",
    "http://www.w3.org/2001/XMLSchema");

// Create the top-level Customer element.
XmlSchemaElement customerElement = new XmlSchemaElement();
customerElement.Name = "Customer";

// Create an anonymous complex type for the Customer element.
XmlSchemaComplexType customerType = new XmlSchemaComplexType();
XmlSchemaSequence sequence = new XmlSchemaSequence();
sequence.Items.Add(firstNameElement);
sequence.Items.Add(lastNameElement);
customerType.Particle = sequence;

// Add the CustomerId attribute to the complex type.
customerType.Attributes.Add(idAttribute);

// Set the SchemaType of the Customer element to
// the anonymous complex type created above.
customerElement.SchemaType = customerType;
' Create the simple type for the LastName element.
Dim lastNameType As XmlSchemaSimpleType = New XmlSchemaSimpleType()
lastNameType.Name = "LastNameType"
Dim lastNameRestriction As XmlSchemaSimpleTypeRestriction = _
    New XmlSchemaSimpleTypeRestriction()
lastNameRestriction.BaseTypeName = _
    New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
Dim maxLength As XmlSchemaMaxLengthFacet = New XmlSchemaMaxLengthFacet()
maxLength.Value = "20"
lastNameRestriction.Facets.Add(maxLength)
lastNameType.Content = lastNameRestriction

' Associate the elements and attributes with their types.
' Built-in type.
firstNameElement.SchemaTypeName = _
    New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' User-defined type.
lastNameElement.SchemaTypeName = _
    New XmlQualifiedName("LastNameType", "http://www.tempuri.org")
' Built-in type.
idAttribute.SchemaTypeName = New XmlQualifiedName("positiveInteger", _
    "http://www.w3.org/2001/XMLSchema")

' Create the top-level Customer element.
Dim customerElement As XmlSchemaElement = New XmlSchemaElement()
customerElement.Name = "Customer"

' Create an anonymous complex type for the Customer element.
Dim customerType As XmlSchemaComplexType = New XmlSchemaComplexType()
Dim sequence As XmlSchemaSequence = New XmlSchemaSequence()
sequence.Items.Add(firstNameElement)
sequence.Items.Add(lastNameElement)
customerType.Particle = sequence

' Add the CustomerId attribute to the complex type.
customerType.Attributes.Add(idAttribute)

' Set the SchemaType of the Customer element to
' the anonymous complex type created above.
customerElement.SchemaType = customerType

スキーマの作成とコンパイル

この時点で、子要素と属性 (それらに対応する型) および最上位の Customer 要素が SOM API を使用してメモリ内に作成されています。 以下のコード サンプルでは、XmlSchema クラスを使用してスキーマ要素が作成され、XmlSchema.Items プロパティを使用して最上位の要素と型が追加されます。また、XmlSchemaSet クラスを使用して完全なスキーマがコンパイルされて、コンソールに出力されます。

// Create an empty schema.
XmlSchema^ customerSchema = gcnew XmlSchema();
customerSchema->TargetNamespace = "http://www.tempuri.org";

// Add all top-level element and types to the schema
customerSchema->Items->Add(customerElement);
customerSchema->Items->Add(lastNameType);

// Create an XmlSchemaSet to compile the customer schema.
XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallback);
schemaSet->Add(customerSchema);
schemaSet->Compile();

for each (XmlSchema^ schema in schemaSet->Schemas())
{
    customerSchema = schema;
}

// Write the complete schema to the Console.
customerSchema->Write(Console::Out);
// Create an empty schema.
XmlSchema customerSchema = new XmlSchema();
customerSchema.TargetNamespace = "http://www.tempuri.org";

// Add all top-level element and types to the schema
customerSchema.Items.Add(customerElement);
customerSchema.Items.Add(lastNameType);

// Create an XmlSchemaSet to compile the customer schema.
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
schemaSet.Add(customerSchema);
schemaSet.Compile();

foreach (XmlSchema schema in schemaSet.Schemas())
{
    customerSchema = schema;
}

// Write the complete schema to the Console.
customerSchema.Write(Console.Out);
' Create an empty schema.
Dim customerSchema As XmlSchema = New XmlSchema()
customerSchema.TargetNamespace = "http://www.tempuri.org"

' Add all top-level element and types to the schema
customerSchema.Items.Add(customerElement)
customerSchema.Items.Add(lastNameType)

' Create an XmlSchemaSet to compile the customer schema.
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallback
schemaSet.Add(customerSchema)
schemaSet.Compile()

For Each schema As XmlSchema In schemaSet.Schemas()
    customerSchema = schema
Next

' Write the complete schema to the Console.
customerSchema.Write(Console.Out)

XmlSchemaSet.Compile メソッドは、XML スキーマの規則を基準としてカスタム スキーマを検証し、スキーマ コンパイル後のプロパティを使用できるようにします。

Note

SOM API のスキーマ コンパイル後のプロパティは、スキーマ検証後の情報セットとは異なります。

ValidationEventHandler に追加される XmlSchemaSet は、コールバック メソッド ValidationCallback を呼び出してスキーマ検証時の警告およびエラーを処理するデリゲートになります。

以下に、完全なコード サンプルおよびコンソールに出力されるカスタム スキーマを示します。

#using <System.Xml.dll>

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

ref class XmlSchemaCreateExample
{
public:

    static void Main()
    {
        // Create the FirstName and LastName elements.
        XmlSchemaElement^ firstNameElement = gcnew XmlSchemaElement();
        firstNameElement->Name = "FirstName";
        XmlSchemaElement^ lastNameElement = gcnew XmlSchemaElement();
        lastNameElement->Name = "LastName";

        // Create CustomerId attribute.
        XmlSchemaAttribute^ idAttribute = gcnew XmlSchemaAttribute();
        idAttribute->Name = "CustomerId";
        idAttribute->Use = XmlSchemaUse::Required;

        // Create the simple type for the LastName element.
        XmlSchemaSimpleType^ lastNameType = gcnew XmlSchemaSimpleType();
        lastNameType->Name = "LastNameType";
        XmlSchemaSimpleTypeRestriction^ lastNameRestriction =
            gcnew XmlSchemaSimpleTypeRestriction();
        lastNameRestriction->BaseTypeName =
            gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        XmlSchemaMaxLengthFacet^ maxLength = gcnew XmlSchemaMaxLengthFacet();
        maxLength->Value = "20";
        lastNameRestriction->Facets->Add(maxLength);
        lastNameType->Content = lastNameRestriction;

        // Associate the elements and attributes with their types.
        // Built-in type.
        firstNameElement->SchemaTypeName =
            gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        // User-defined type.
        lastNameElement->SchemaTypeName =
            gcnew XmlQualifiedName("LastNameType", "http://www.tempuri.org");
        // Built-in type.
        idAttribute->SchemaTypeName = gcnew XmlQualifiedName("positiveInteger",
            "http://www.w3.org/2001/XMLSchema");
        
        // Create the top-level Customer element.
        XmlSchemaElement^ customerElement = gcnew XmlSchemaElement();
        customerElement->Name = "Customer";

        // Create an anonymous complex type for the Customer element.
        XmlSchemaComplexType^ customerType = gcnew XmlSchemaComplexType();
        XmlSchemaSequence^ sequence = gcnew XmlSchemaSequence();
        sequence->Items->Add(firstNameElement);
        sequence->Items->Add(lastNameElement);
        customerType->Particle = sequence;
        
        // Add the CustomerId attribute to the complex type.
        customerType->Attributes->Add(idAttribute);

        // Set the SchemaType of the Customer element to
        // the anonymous complex type created above.
        customerElement->SchemaType = customerType;
        
        // Create an empty schema.
        XmlSchema^ customerSchema = gcnew XmlSchema();
        customerSchema->TargetNamespace = "http://www.tempuri.org";

        // Add all top-level element and types to the schema
        customerSchema->Items->Add(customerElement);
        customerSchema->Items->Add(lastNameType);

        // Create an XmlSchemaSet to compile the customer schema.
        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallback);
        schemaSet->Add(customerSchema);
        schemaSet->Compile();
        
        for each (XmlSchema^ schema in schemaSet->Schemas())
        {
            customerSchema = schema;
        }

        // Write the complete schema to the Console.
        customerSchema->Write(Console::Out);
    }

    static void ValidationCallback(Object^ sender, ValidationEventArgs^ args)
    {
        if (args->Severity == XmlSeverityType::Warning)
            Console::Write("WARNING: ");
        else if (args->Severity == XmlSeverityType::Error)
            Console::Write("ERROR: ");

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

int main()
{
    XmlSchemaCreateExample::Main();
    return 0;
}
using System;
using System.Xml;
using System.Xml.Schema;

class XmlSchemaCreateExample
{
    static void Main(string[] args)
    {
        // Create the FirstName and LastName elements.
        XmlSchemaElement firstNameElement = new XmlSchemaElement();
        firstNameElement.Name = "FirstName";
        XmlSchemaElement lastNameElement = new XmlSchemaElement();
        lastNameElement.Name = "LastName";

        // Create CustomerId attribute.
        XmlSchemaAttribute idAttribute = new XmlSchemaAttribute();
        idAttribute.Name = "CustomerId";
        idAttribute.Use = XmlSchemaUse.Required;

        // Create the simple type for the LastName element.
        XmlSchemaSimpleType lastNameType = new XmlSchemaSimpleType();
        lastNameType.Name = "LastNameType";
        XmlSchemaSimpleTypeRestriction lastNameRestriction =
            new XmlSchemaSimpleTypeRestriction();
        lastNameRestriction.BaseTypeName =
            new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        XmlSchemaMaxLengthFacet maxLength = new XmlSchemaMaxLengthFacet();
        maxLength.Value = "20";
        lastNameRestriction.Facets.Add(maxLength);
        lastNameType.Content = lastNameRestriction;

        // Associate the elements and attributes with their types.
        // Built-in type.
        firstNameElement.SchemaTypeName =
            new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        // User-defined type.
        lastNameElement.SchemaTypeName =
            new XmlQualifiedName("LastNameType", "http://www.tempuri.org");
        // Built-in type.
        idAttribute.SchemaTypeName = new XmlQualifiedName("positiveInteger",
            "http://www.w3.org/2001/XMLSchema");

        // Create the top-level Customer element.
        XmlSchemaElement customerElement = new XmlSchemaElement();
        customerElement.Name = "Customer";

        // Create an anonymous complex type for the Customer element.
        XmlSchemaComplexType customerType = new XmlSchemaComplexType();
        XmlSchemaSequence sequence = new XmlSchemaSequence();
        sequence.Items.Add(firstNameElement);
        sequence.Items.Add(lastNameElement);
        customerType.Particle = sequence;

        // Add the CustomerId attribute to the complex type.
        customerType.Attributes.Add(idAttribute);

        // Set the SchemaType of the Customer element to
        // the anonymous complex type created above.
        customerElement.SchemaType = customerType;

        // Create an empty schema.
        XmlSchema customerSchema = new XmlSchema();
        customerSchema.TargetNamespace = "http://www.tempuri.org";

        // Add all top-level element and types to the schema
        customerSchema.Items.Add(customerElement);
        customerSchema.Items.Add(lastNameType);

        // Create an XmlSchemaSet to compile the customer schema.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
        schemaSet.Add(customerSchema);
        schemaSet.Compile();

        foreach (XmlSchema schema in schemaSet.Schemas())
        {
            customerSchema = schema;
        }

        // Write the complete schema to the Console.
        customerSchema.Write(Console.Out);
    }

    static void ValidationCallback(object sender, ValidationEventArgs args)
    {
        if (args.Severity == XmlSeverityType.Warning)
            Console.Write("WARNING: ");
        else if (args.Severity == XmlSeverityType.Error)
            Console.Write("ERROR: ");

        Console.WriteLine(args.Message);
    }
}
Imports System.Xml
Imports System.Xml.Schema

Class XmlSchemaCreateExample

    Shared Sub Main()

        ' Create the FirstName and LastName elements.
        Dim firstNameElement As XmlSchemaElement = New XmlSchemaElement()
        firstNameElement.Name = "FirstName"
        Dim lastNameElement As XmlSchemaElement = New XmlSchemaElement()
        lastNameElement.Name = "LastName"

        ' Create CustomerId attribute.
        Dim idAttribute As XmlSchemaAttribute = New XmlSchemaAttribute()
        idAttribute.Name = "CustomerId"
        idAttribute.Use = XmlSchemaUse.Required

        ' Create the simple type for the LastName element.
        Dim lastNameType As XmlSchemaSimpleType = New XmlSchemaSimpleType()
        lastNameType.Name = "LastNameType"
        Dim lastNameRestriction As XmlSchemaSimpleTypeRestriction = _
            New XmlSchemaSimpleTypeRestriction()
        lastNameRestriction.BaseTypeName = _
            New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        Dim maxLength As XmlSchemaMaxLengthFacet = New XmlSchemaMaxLengthFacet()
        maxLength.Value = "20"
        lastNameRestriction.Facets.Add(maxLength)
        lastNameType.Content = lastNameRestriction

        ' Associate the elements and attributes with their types.
        ' Built-in type.
        firstNameElement.SchemaTypeName = _
            New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        ' User-defined type.
        lastNameElement.SchemaTypeName = _
            New XmlQualifiedName("LastNameType", "http://www.tempuri.org")
        ' Built-in type.
        idAttribute.SchemaTypeName = New XmlQualifiedName("positiveInteger", _
            "http://www.w3.org/2001/XMLSchema")

        ' Create the top-level Customer element.
        Dim customerElement As XmlSchemaElement = New XmlSchemaElement()
        customerElement.Name = "Customer"

        ' Create an anonymous complex type for the Customer element.
        Dim customerType As XmlSchemaComplexType = New XmlSchemaComplexType()
        Dim sequence As XmlSchemaSequence = New XmlSchemaSequence()
        sequence.Items.Add(firstNameElement)
        sequence.Items.Add(lastNameElement)
        customerType.Particle = sequence

        ' Add the CustomerId attribute to the complex type.
        customerType.Attributes.Add(idAttribute)

        ' Set the SchemaType of the Customer element to
        ' the anonymous complex type created above.
        customerElement.SchemaType = customerType

        ' Create an empty schema.
        Dim customerSchema As XmlSchema = New XmlSchema()
        customerSchema.TargetNamespace = "http://www.tempuri.org"

        ' Add all top-level element and types to the schema
        customerSchema.Items.Add(customerElement)
        customerSchema.Items.Add(lastNameType)

        ' Create an XmlSchemaSet to compile the customer schema.
        Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallback
        schemaSet.Add(customerSchema)
        schemaSet.Compile()

        For Each schema As XmlSchema In schemaSet.Schemas()
            customerSchema = schema
        Next

        ' Write the complete schema to the Console.
        customerSchema.Write(Console.Out)
    End Sub

    Shared Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs)
        If args.Severity = XmlSeverityType.Warning Then
            Console.Write("WARNING: ")
        Else
            If args.Severity = XmlSeverityType.Error Then
                Console.Write("ERROR: ")
            End If
        End If
        Console.WriteLine(args.Message)
    End Sub
End Class
<?xml version="1.0" encoding="utf-8"?>  
<xs:schema xmlns:tns="http://www.tempuri.org" targetNamespace="http://www.tempuri.org" xmlns:xs="http://www.w3.org/2001/XMLSchema">  
   <xs:element name="Customer">  
      <xs:complexType>  
         <xs:sequence>  
            <xs:element name="FirstName" type="xs:string" />  
            <xs:element name="LastName" type="tns:LastNameType" />  
         </xs:sequence>  
         <xs:attribute name="CustomerId" type="xs:positiveInteger" use="required" />  
      </xs:complexType>  
   </xs:element>  
   <xs:simpleType name="LastNameType">  
      <xs:restriction base="xs:string">  
         <xs:maxLength value="20" />  
      </xs:restriction>  
   </xs:simpleType>  
</xs:schema>  

関連項目