XmlSchemaChoice クラス
子の 1 つだけをインスタンスに表示できるようにします。W3C (World Wide Web Consortium) choice (コンポジタ) 要素を表します。
この型のすべてのメンバの一覧については、XmlSchemaChoice メンバ を参照してください。
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaParticle
System.Xml.Schema.XmlSchemaGroupBase
System.Xml.Schema.XmlSchemaChoice
Public Class XmlSchemaChoice
Inherits XmlSchemaGroupBase
[C#]
public class XmlSchemaChoice : XmlSchemaGroupBase
[C++]
public __gc class XmlSchemaChoice : public XmlSchemaGroupBase
[JScript]
public class XmlSchemaChoice extends XmlSchemaGroupBase
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
使用例
[Visual Basic, C#, C++] choice 要素を作成する例を次に示します。
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:element name="selected"/>
Dim xeSelected As New XmlSchemaElement()
xeSelected.Name = "selected"
schema.Items.Add(xeSelected)
' <xs:element name="unselected"/>
Dim xeUnselected As New XmlSchemaElement()
xeUnselected.Name = "unselected"
schema.Items.Add(xeUnselected)
' <xs:element name="dimpled"/>
Dim xeDimpled As New XmlSchemaElement()
xeDimpled.Name = "dimpled"
schema.Items.Add(xeDimpled)
' <xs:element name="perforated"/>
Dim xePerforated As New XmlSchemaElement()
xePerforated.Name = "perforated"
schema.Items.Add(xePerforated)
' <xs:complexType name="chadState">
Dim chadState As New XmlSchemaComplexType()
schema.Items.Add(chadState)
chadState.Name = "chadState"
' <xs:choice minOccurs="1" maxOccurs="1">
Dim choice As New XmlSchemaChoice()
chadState.Particle = choice
choice.MinOccurs = 1
choice.MaxOccurs = 1
' <xs:element ref="selected"/>
Dim elementSelected As New XmlSchemaElement()
choice.Items.Add(elementSelected)
elementSelected.RefName = New XmlQualifiedName("selected")
' <xs:element ref="unselected"/>
Dim elementUnselected As New XmlSchemaElement()
choice.Items.Add(elementUnselected)
elementUnselected.RefName = New XmlQualifiedName("unselected")
' <xs:element ref="dimpled"/>
Dim elementDimpled As New XmlSchemaElement()
choice.Items.Add(elementDimpled)
elementDimpled.RefName = New XmlQualifiedName("dimpled")
' <xs:element ref="perforated"/>
Dim elementPerforated As New XmlSchemaElement()
choice.Items.Add(elementPerforated)
elementPerforated.RefName = New XmlQualifiedName("perforated")
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="selected"/>
XmlSchemaElement xeSelected = new XmlSchemaElement();
xeSelected.Name = "selected";
schema.Items.Add(xeSelected);
// <xs:element name="unselected"/>
XmlSchemaElement xeUnselected = new XmlSchemaElement();
xeUnselected.Name = "unselected";
schema.Items.Add(xeUnselected);
// <xs:element name="dimpled"/>
XmlSchemaElement xeDimpled = new XmlSchemaElement();
xeDimpled.Name = "dimpled";
schema.Items.Add(xeDimpled);
// <xs:element name="perforated"/>
XmlSchemaElement xePerforated = new XmlSchemaElement();
xePerforated.Name = "perforated";
schema.Items.Add(xePerforated);
// <xs:complexType name="chadState">
XmlSchemaComplexType chadState = new XmlSchemaComplexType();
schema.Items.Add(chadState);
chadState.Name = "chadState";
// <xs:choice minOccurs="1" maxOccurs="1">
XmlSchemaChoice choice = new XmlSchemaChoice();
chadState.Particle = choice;
choice.MinOccurs = 1;
choice.MaxOccurs = 1;
// <xs:element ref="selected"/>
XmlSchemaElement elementSelected = new XmlSchemaElement();
choice.Items.Add(elementSelected);
elementSelected.RefName = new XmlQualifiedName("selected");
// <xs:element ref="unselected"/>
XmlSchemaElement elementUnselected = new XmlSchemaElement();
choice.Items.Add(elementUnselected);
elementUnselected.RefName = new XmlQualifiedName("unselected");
// <xs:element ref="dimpled"/>
XmlSchemaElement elementDimpled = new XmlSchemaElement();
choice.Items.Add(elementDimpled);
elementDimpled.RefName = new XmlQualifiedName("dimpled");
// <xs:element ref="perforated"/>
XmlSchemaElement elementPerforated = new XmlSchemaElement();
choice.Items.Add(elementPerforated);
elementPerforated.RefName = new XmlQualifiedName("perforated");
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="selected"/>
XmlSchemaElement* xeSelected = new XmlSchemaElement();
xeSelected->Name = S"selected";
schema->Items->Add(xeSelected);
// <xs:element name="unselected"/>
XmlSchemaElement* xeUnselected = new XmlSchemaElement();
xeUnselected->Name = S"unselected";
schema->Items->Add(xeUnselected);
// <xs:element name="dimpled"/>
XmlSchemaElement* xeDimpled = new XmlSchemaElement();
xeDimpled->Name = S"dimpled";
schema->Items->Add(xeDimpled);
// <xs:element name="perforated"/>
XmlSchemaElement* xePerforated = new XmlSchemaElement();
xePerforated->Name = S"perforated";
schema->Items->Add(xePerforated);
// <xs:complexType name="chadState">
XmlSchemaComplexType* chadState = new XmlSchemaComplexType();
schema->Items->Add(chadState);
chadState->Name = S"chadState";
// <xs:choice minOccurs="1" maxOccurs="1">
XmlSchemaChoice* choice = new XmlSchemaChoice();
chadState->Particle = choice;
choice->MinOccurs = 1;
choice->MaxOccurs = 1;
// <xs:element ref="selected"/>
XmlSchemaElement* elementSelected = new XmlSchemaElement();
choice->Items->Add(elementSelected);
elementSelected->RefName = new XmlQualifiedName(S"selected");
// <xs:element ref="unselected"/>
XmlSchemaElement* elementUnselected = new XmlSchemaElement();
choice->Items->Add(elementUnselected);
elementUnselected->RefName = new XmlQualifiedName(S"unselected");
// <xs:element ref="dimpled"/>
XmlSchemaElement* elementDimpled = new XmlSchemaElement();
choice->Items->Add(elementDimpled);
elementDimpled->RefName = new XmlQualifiedName(S"dimpled");
// <xs:element ref="perforated"/>
XmlSchemaElement* elementPerforated = new XmlSchemaElement();
choice->Items->Add(elementPerforated);
elementPerforated->RefName = new XmlQualifiedName(S"perforated");
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="selected"/>
<xs:element name="unselected"/>
<xs:element name="dimpled"/>
<xs:element name="perforated"/>
<xs:complexType name="chadState">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element ref="selected"/>
<xs:element ref="unselected"/>
<xs:element ref="dimpled"/>
<xs:element ref="perforated"/>
</xs:choice>
</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 内)