XmlSchemaElement クラス
すべてのパーティクル型の基本クラス。XML ドキュメント内の要素を記述するために使用します。W3C (World Wide Web Consortium) element 要素を表します。
この型のすべてのメンバの一覧については、XmlSchemaElement メンバ を参照してください。
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaParticle
System.Xml.Schema.XmlSchemaElement
Public Class XmlSchemaElement
Inherits XmlSchemaParticle
[C#]
public class XmlSchemaElement : XmlSchemaParticle
[C++]
public __gc class XmlSchemaElement : public XmlSchemaParticle
[JScript]
public class XmlSchemaElement extends XmlSchemaParticle
スレッドセーフ
この型の public static (Visual Basicでは Shared) のすべてのメンバは、マルチスレッド操作で安全に使用できます。インスタンスのメンバの場合は、スレッドセーフであるとは限りません。
使用例
[Visual Basic, C#, C++] element 要素を作成する例を次に示します。
Imports System
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema as New XmlSchema()
' <xs:element name="cat" type="string"/>
Dim elementCat as New XmlSchemaElement()
schema.Items.Add(elementCat)
elementCat.Name = "cat"
elementCat.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <xs:element name="dog" type="string"/>
Dim elementDog as New XmlSchemaElement()
schema.Items.Add(elementDog)
elementDog.Name = "dog"
elementDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <xs:element name="redDog" substitutionGroup="dog" />
Dim elementRedDog as New XmlSchemaElement()
schema.Items.Add(elementRedDog)
elementRedDog.Name = "redDog"
elementRedDog.SubstitutionGroup = new XmlQualifiedName("dog")
' <xs:element name="brownDog" substitutionGroup ="dog" />
Dim elementBrownDog as New XmlSchemaElement()
schema.Items.Add(elementBrownDog)
elementBrownDog.Name = "brownDog"
elementBrownDog.SubstitutionGroup = new XmlQualifiedName("dog")
' <xs:element name="pets">
Dim elementPets as New XmlSchemaElement()
schema.Items.Add(elementPets)
elementPets.Name = "pets"
' <xs:complexType>
Dim complexType as New XmlSchemaComplexType()
elementPets.SchemaType = complexType
' <xs:choice minOccurs="0" maxOccurs="unbounded">
Dim choice as New XmlSchemaChoice()
complexType.Particle = choice
choice.MinOccurs = 0
choice.MaxOccursString = "unbounded"
' <xs:element ref="cat"/>
Dim catRef as New XmlSchemaElement()
choice.Items.Add(catRef)
catRef.RefName = new XmlQualifiedName("cat")
' <xs:element ref="dog"/>
Dim dogRef as New XmlSchemaElement()
choice.Items.Add(dogRef)
dogRef.RefName = new XmlQualifiedName("dog")
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
Public Shared Sub ValidationCallbackOne(sender as object, args as ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub
End Class
[C#]
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples {
public static void Main() {
XmlSchema schema = new XmlSchema();
// <xs:element name="cat" type="string"/>
XmlSchemaElement elementCat = new XmlSchemaElement();
schema.Items.Add(elementCat);
elementCat.Name = "cat";
elementCat.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="dog" type="string"/>
XmlSchemaElement elementDog = new XmlSchemaElement();
schema.Items.Add(elementDog);
elementDog.Name = "dog";
elementDog.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="redDog" substitutionGroup="dog" />
XmlSchemaElement elementRedDog = new XmlSchemaElement();
schema.Items.Add(elementRedDog);
elementRedDog.Name = "redDog";
elementRedDog.SubstitutionGroup = new XmlQualifiedName("dog");
// <xs:element name="brownDog" substitutionGroup ="dog" />
XmlSchemaElement elementBrownDog = new XmlSchemaElement();
schema.Items.Add(elementBrownDog);
elementBrownDog.Name = "brownDog";
elementBrownDog.SubstitutionGroup = new XmlQualifiedName("dog");
// <xs:element name="pets">
XmlSchemaElement elementPets = new XmlSchemaElement();
schema.Items.Add(elementPets);
elementPets.Name = "pets";
// <xs:complexType>
XmlSchemaComplexType complexType = new XmlSchemaComplexType();
elementPets.SchemaType = complexType;
// <xs:choice minOccurs="0" maxOccurs="unbounded">
XmlSchemaChoice choice = new XmlSchemaChoice();
complexType.Particle = choice;
choice.MinOccurs = 0;
choice.MaxOccursString = "unbounded";
// <xs:element ref="cat"/>
XmlSchemaElement catRef = new XmlSchemaElement();
choice.Items.Add(catRef);
catRef.RefName = new XmlQualifiedName("cat");
// <xs:element ref="dog"/>
XmlSchemaElement dogRef = new XmlSchemaElement();
choice.Items.Add(dogRef);
dogRef.RefName = new XmlQualifiedName("dog");
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 ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) {
Console::WriteLine(args->Message);
}
};
int main() {
XmlSchema* schema = new XmlSchema();
// <xs:element name="cat" type="string"/>
XmlSchemaElement* elementCat = new XmlSchemaElement();
schema->Items->Add(elementCat);
elementCat->Name = S"cat";
elementCat->SchemaTypeName = new XmlQualifiedName(S"String*", S"http://www.w3.org/2001/XMLSchema");
// <xs:element name="dog" type="string"/>
XmlSchemaElement* elementDog = new XmlSchemaElement();
schema->Items->Add(elementDog);
elementDog->Name = S"dog";
elementDog->SchemaTypeName = new XmlQualifiedName(S"String*", S"http://www.w3.org/2001/XMLSchema");
// <xs:element name="redDog" substitutionGroup="dog" />
XmlSchemaElement* elementRedDog = new XmlSchemaElement();
schema->Items->Add(elementRedDog);
elementRedDog->Name = S"redDog";
elementRedDog->SubstitutionGroup = new XmlQualifiedName(S"dog");
// <xs:element name="brownDog" substitutionGroup="dog" />
XmlSchemaElement* elementBrownDog = new XmlSchemaElement();
schema->Items->Add(elementBrownDog);
elementBrownDog->Name = S"brownDog";
elementBrownDog->SubstitutionGroup = new XmlQualifiedName(S"dog");
// <xs:element name="pets">
XmlSchemaElement* elementPets = new XmlSchemaElement();
schema->Items->Add(elementPets);
elementPets->Name = S"pets";
// <xs:complexType>
XmlSchemaComplexType* complexType = new XmlSchemaComplexType();
elementPets->SchemaType = complexType;
// <xs:choice minOccurs="0" maxOccurs="unbounded">
XmlSchemaChoice* choice = new XmlSchemaChoice();
complexType->Particle = choice;
choice->MinOccurs = 0;
choice->MaxOccursString = S"unbounded";
// <xs:element ref="cat"/>
XmlSchemaElement* catRef = new XmlSchemaElement();
choice->Items->Add(catRef);
catRef->RefName = new XmlQualifiedName(S"cat");
// <xs:element ref="dog"/>
XmlSchemaElement* dogRef = new XmlSchemaElement();
choice->Items->Add(dogRef);
dogRef->RefName = new XmlQualifiedName(S"dog");
schema->Compile(new ValidationEventHandler(0, XMLSchemaExamples::ValidationCallbackOne));
XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr->AddNamespace(S"xs", S"http://www.w3.org/2001/XMLSchema");
schema->Write(Console::Out, nsmgr);
}
[Visual Basic, C#, C++] 前述のコード例に対して使用される XML ファイルを次に示します。
<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="cat" type="xs:string"/>
<xs:element name="dog" type="xs:string"/>
<xs:element name="redDog" substitutionGroup="dog" />
<xs:element name="brownDog" substitutionGroup ="dog" />
<xs:element name="pets">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="cat"/>
<xs:element ref="dog"/>
</xs:choice>
</xs:complexType>
</xs:element>
</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 内)