次の方法で共有


XmlSchemaGroup クラス

複合型から参照される schema レベルのグループを定義するクラス。要素宣言セットをグループ化し、グループとして複合型定義に組み込むことができるようにします。W3C (World Wide Web Consortium) group 要素を表します。

この型のすべてのメンバの一覧については、XmlSchemaGroup メンバ を参照してください。

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaAnnotated
         System.Xml.Schema.XmlSchemaGroup

Public Class XmlSchemaGroup
   Inherits XmlSchemaAnnotated
[C#]
public class XmlSchemaGroup : XmlSchemaAnnotated
[C++]
public __gc class XmlSchemaGroup : public XmlSchemaAnnotated
[JScript]
public class XmlSchemaGroup extends XmlSchemaAnnotated

スレッドセーフ

この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。

使用例

[Visual Basic, C#, C++] XmlSchemaGroup クラスを使用する例を次に示します。

 
Option Explicit
Option Strict

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

Class XMLSchemaExamples
    
    Public Shared Sub Main()
        
        Dim schema As New XmlSchema()
        
        ' <xs:element name="thing1" type="xs:string"/>
        Dim elementThing1 As New XmlSchemaElement()
        schema.Items.Add(elementThing1)
        elementThing1.Name = "thing1"
        elementThing1.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:element name="thing2" type="xs:string"/>
        Dim elementThing2 As New XmlSchemaElement()
        schema.Items.Add(elementThing2)
        elementThing2.Name = "thing2"
        elementThing2.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:element name="thing3" type="xs:string"/>
        Dim elementThing3 As New XmlSchemaElement()
        schema.Items.Add(elementThing3)
        elementThing3.Name = "thing3"
        elementThing3.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:attribute name="myAttribute" type="xs:decimal"/>
        Dim myAttribute As New XmlSchemaAttribute()
        schema.Items.Add(myAttribute)
        myAttribute.Name = "myAttribute"
        myAttribute.SchemaTypeName = New XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema")
        
        ' <xs:group name="myGroupOfThings">
        Dim myGroupOfThings As New XmlSchemaGroup()
        schema.Items.Add(myGroupOfThings)
        myGroupOfThings.Name = "myGroupOfThings"
        
        ' <xs:sequence>
        Dim sequence As New XmlSchemaSequence()
        myGroupOfThings.Particle = sequence
        
        ' <xs:element ref="thing1"/>
        Dim elementThing1Ref As New XmlSchemaElement()
        sequence.Items.Add(elementThing1Ref)
        elementThing1Ref.RefName = New XmlQualifiedName("thing1")
        
        ' <xs:element ref="thing2"/>
        Dim elementThing2Ref As New XmlSchemaElement()
        sequence.Items.Add(elementThing2Ref)
        elementThing2Ref.RefName = New XmlQualifiedName("thing2")
        
        ' <xs:element ref="thing3"/>
        Dim elementThing3Ref As New XmlSchemaElement()
        sequence.Items.Add(elementThing3Ref)
        elementThing3Ref.RefName = New XmlQualifiedName("thing3")
        
        ' <xs:complexType name="myComplexType">
        Dim myComplexType As New XmlSchemaComplexType()
        schema.Items.Add(myComplexType)
        myComplexType.Name = "myComplexType"
        
        ' <xs:group ref="myGroupOfThings"/>
        Dim myGroupOfThingsRef As New XmlSchemaGroupRef()
        myComplexType.Particle = myGroupOfThingsRef
        myGroupOfThingsRef.RefName = New XmlQualifiedName("myGroupOfThings")
        
        ' <xs:attribute ref="myAttribute"/>
        Dim myAttributeRef As New XmlSchemaAttribute()
        myComplexType.Attributes.Add(myAttributeRef)
        myAttributeRef.RefName = New XmlQualifiedName("myAttribute")
        
        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:element name="thing1" type="xs:string"/>
        XmlSchemaElement elementThing1 = new XmlSchemaElement();
        schema.Items.Add(elementThing1);
        elementThing1.Name = "thing1";
        elementThing1.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="thing2" type="xs:string"/>
        XmlSchemaElement elementThing2 = new XmlSchemaElement();
        schema.Items.Add(elementThing2);
        elementThing2.Name = "thing2";
        elementThing2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:element name="thing3" type="xs:string"/>
        XmlSchemaElement elementThing3 = new XmlSchemaElement();
        schema.Items.Add(elementThing3);
        elementThing3.Name = "thing3";
        elementThing3.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:attribute name="myAttribute" type="xs:decimal"/>
        XmlSchemaAttribute myAttribute = new XmlSchemaAttribute();
        schema.Items.Add(myAttribute);
        myAttribute.Name = "myAttribute";
        myAttribute.SchemaTypeName = new XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema");
        
        // <xs:group name="myGroupOfThings">
        XmlSchemaGroup myGroupOfThings = new XmlSchemaGroup();
        schema.Items.Add(myGroupOfThings);
        myGroupOfThings.Name = "myGroupOfThings";
        
        // <xs:sequence>
        XmlSchemaSequence sequence = new XmlSchemaSequence();
        myGroupOfThings.Particle = sequence;

        // <xs:element ref="thing1"/>
        XmlSchemaElement elementThing1Ref = new XmlSchemaElement();
        sequence.Items.Add(elementThing1Ref);
        elementThing1Ref.RefName = new XmlQualifiedName("thing1");
        
        // <xs:element ref="thing2"/>
        XmlSchemaElement elementThing2Ref = new XmlSchemaElement();
        sequence.Items.Add(elementThing2Ref);
        elementThing2Ref.RefName = new XmlQualifiedName("thing2");

        // <xs:element ref="thing3"/>
        XmlSchemaElement elementThing3Ref = new XmlSchemaElement();
        sequence.Items.Add(elementThing3Ref);
        elementThing3Ref.RefName = new XmlQualifiedName("thing3");

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType myComplexType = new XmlSchemaComplexType();
        schema.Items.Add(myComplexType);
        myComplexType.Name = "myComplexType";
        
        // <xs:group ref="myGroupOfThings"/>
        XmlSchemaGroupRef myGroupOfThingsRef = new XmlSchemaGroupRef();
        myComplexType.Particle = myGroupOfThingsRef;
        myGroupOfThingsRef.RefName = new XmlQualifiedName("myGroupOfThings");

        // <xs:attribute ref="myAttribute"/>
        XmlSchemaAttribute myAttributeRef = new XmlSchemaAttribute();
        myComplexType.Attributes.Add(myAttributeRef);
        myAttributeRef.RefName = new XmlQualifiedName("myAttribute");

        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:element name="thing1" type="xs:string"/>
        XmlSchemaElement* elementThing1 = new XmlSchemaElement();
        schema->Items->Add(elementThing1);
        elementThing1->Name = S"thing1";
        elementThing1->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:element name="thing2" type="xs:string"/>
        XmlSchemaElement* elementThing2 = new XmlSchemaElement();
        schema->Items->Add(elementThing2);
        elementThing2->Name = S"thing2";
        elementThing2->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");

        // <xs:element name="thing3" type="xs:string"/>
        XmlSchemaElement* elementThing3 = new XmlSchemaElement();
        schema->Items->Add(elementThing3);
        elementThing3->Name = S"thing3";
        elementThing3->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:attribute name="myAttribute" type="xs:decimal"/>
        XmlSchemaAttribute* myAttribute = new XmlSchemaAttribute();
        schema->Items->Add(myAttribute);
        myAttribute->Name = S"myAttribute";
        myAttribute->SchemaTypeName = new XmlQualifiedName(S"decimal", S"http://www.w3.org/2001/XMLSchema");
        
        // <xs:group name="myGroupOfThings">
        XmlSchemaGroup* myGroupOfThings = new XmlSchemaGroup();
        schema->Items->Add(myGroupOfThings);
        myGroupOfThings->Name = S"myGroupOfThings";
        
        // <xs:sequence>
        XmlSchemaSequence* sequence = new XmlSchemaSequence();
        myGroupOfThings->Particle = sequence;

        // <xs:element ref="thing1"/>
        XmlSchemaElement* elementThing1Ref = new XmlSchemaElement();
        sequence->Items->Add(elementThing1Ref);
        elementThing1Ref->RefName = new XmlQualifiedName(S"thing1");
        
        // <xs:element ref="thing2"/>
        XmlSchemaElement* elementThing2Ref = new XmlSchemaElement();
        sequence->Items->Add(elementThing2Ref);
        elementThing2Ref->RefName = new XmlQualifiedName(S"thing2");

        // <xs:element ref="thing3"/>
        XmlSchemaElement* elementThing3Ref = new XmlSchemaElement();
        sequence->Items->Add(elementThing3Ref);
        elementThing3Ref->RefName = new XmlQualifiedName(S"thing3");

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType* myComplexType = new XmlSchemaComplexType();
        schema->Items->Add(myComplexType);
        myComplexType->Name = S"myComplexType";
        
        // <xs:group ref="myGroupOfThings"/>
        XmlSchemaGroupRef* myGroupOfThingsRef = new XmlSchemaGroupRef();
        myComplexType->Particle = myGroupOfThingsRef;
        myGroupOfThingsRef->RefName = new XmlQualifiedName(S"myGroupOfThings");

        // <xs:attribute ref="myAttribute"/>
        XmlSchemaAttribute* myAttributeRef = new XmlSchemaAttribute();
        myComplexType->Attributes->Add(myAttributeRef);
        myAttributeRef->RefName = new XmlQualifiedName(S"myAttribute");

        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++] 前述のコード例に対して生成される XML ファイルを次に示します。

<?xml version="1.0" encoding="IBM437"?>
<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="thing1" type="xs:string"/>
    <xs:element name="thing2" type="xs:string"/>
    <xs:element name="thing3" type="xs:string"/>

    <xs:attribute name="myAttribute" type="xs:decimal"/>

    <xs:group name="myGroupOfThings">
     <xs:sequence>
      <xs:element ref="thing1"/>
      <xs:element ref="thing2"/>
      <xs:element ref="thing3"/>
     </xs:sequence>
    </xs:group>

    <xs:complexType name="myComplexType">
        <xs:group ref="myGroupOfThings"/>
        <xs:attribute ref="myAttribute"/>
    </xs:complexType>
</xs:schema>

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Xml.Schema

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Xml (System.Xml.dll 内)

参照

XmlSchemaGroup メンバ | System.Xml.Schema 名前空間