XmlSchemaElement クラス

定義

World Wide Web Consortium (W3C) で指定された XML スキーマの element 要素を表します。 このクラスは、すべてのパーティクル タイプの基本クラスであり、XML ドキュメント内の要素を記述するために使用されます。

public ref class XmlSchemaElement : System::Xml::Schema::XmlSchemaParticle
public class XmlSchemaElement : System.Xml.Schema.XmlSchemaParticle
type XmlSchemaElement = class
    inherit XmlSchemaParticle
Public Class XmlSchemaElement
Inherits XmlSchemaParticle
継承

次の例では、 element 要素を作成します。

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");

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

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

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)
    {
        Console.WriteLine(args.Message);
    }
}
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")

        Dim schemaSet As New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne

        schemaSet.Add(schema)
        schemaSet.Compile()

        Dim compiledSchema As XmlSchema = Nothing

        For Each schema1 As XmlSchema In schemaSet.Schemas()
            compiledSchema = schema1
        Next

        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
        compiledSchema.Write(Console.Out, nsmgr)

    End Sub

    Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub

End Class

前のコード例では、次の 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>

注釈

Important

  • 不明または信頼されていないソースまたは場所のスキーマは使用しないでください。 これにより、コードのセキュリティが損なわれます。
  • XML スキーマ (インライン スキーマを含む) は、本質的にサービス拒否攻撃に対して脆弱です。信頼されていないシナリオでは受け入れないでください。
  • スキーマ検証エラー メッセージと例外により、コンテンツ モデルまたは URI パスに関する機密情報がスキーマ ファイルに公開される場合があります。 信頼されていない呼び出し元にこの情報を公開しないように注意してください。

コンストラクター

名前 説明
XmlSchemaElement()

XmlSchemaElement クラスの新しいインスタンスを初期化します。

プロパティ

名前 説明
Annotation

annotation プロパティを取得または設定します。

(継承元 XmlSchemaAnnotated)
Block

Block派生を取得または設定します。

BlockResolved

Block プロパティのコンパイル後の値を取得します。

Constraints

要素の制約のコレクションを取得します。

DefaultValue

コンテンツが単純型の場合、または要素のコンテンツが textOnlyされている場合は、要素の既定値を取得または設定します。

ElementSchemaType

要素のSchemaTypeまたはSchemaTypeName値に基づいて、要素の型を表すXmlSchemaType オブジェクトを取得します。

ElementType
古い.
古い.

XmlSchemaElement プロパティのコンパイル後の値を保持する要素のXmlSchemaElementまたはElementTypeに基づいて共通言語ランタイム (CLR) オブジェクトを取得します。

Final

それ以上の派生が許可されていないことを示す Final プロパティを取得または設定します。

FinalResolved

Final プロパティのコンパイル後の値を取得します。

FixedValue

固定値を取得または設定します。

Form

要素のフォームを取得または設定します。

Id

文字列 ID を取得または設定します。

(継承元 XmlSchemaAnnotated)
IsAbstract

インスタンス ドキュメントで要素を使用できるかどうかを示す情報を取得または設定します。

IsNillable

インスタンス データで xsi:nil が発生できるかどうかを示す情報を取得または設定します。 明示的な nil 値を要素に割り当てることができるかどうかを示します。

LineNumber

schema要素が参照するファイル内の行番号を取得または設定します。

(継承元 XmlSchemaObject)
LinePosition

schema要素が参照するファイル内の行位置を取得または設定します。

(継承元 XmlSchemaObject)
MaxOccurs

パーティクルが発生する最大回数を取得または設定します。

(継承元 XmlSchemaParticle)
MaxOccursString

数値を文字列値として取得または設定します。 パーティクルが発生する可能性がある最大回数。

(継承元 XmlSchemaParticle)
MinOccurs

パーティクルが発生する最小回数を取得または設定します。

(継承元 XmlSchemaParticle)
MinOccursString

数値を文字列値として取得または設定します。 パーティクルが発生する最小回数。

(継承元 XmlSchemaParticle)
Name

要素の名前を取得または設定します。

Namespaces

このスキーマ オブジェクトで使用する XmlSerializerNamespaces を取得または設定します。

(継承元 XmlSchemaObject)
Parent

この XmlSchemaObjectの親を取得または設定します。

(継承元 XmlSchemaObject)
QualifiedName

指定された要素の実際の修飾名を取得します。

RefName

このスキーマで宣言されている要素 (または指定した名前空間によって示される別のスキーマ) の参照名を取得または設定します。

SchemaType

要素の型を取得または設定します。 複合型または単純型を指定できます。

SchemaTypeName

このスキーマで定義されている組み込みデータ型の名前、または指定した名前空間によって示される別のスキーマの名前を取得または設定します。

SourceUri

スキーマを読み込んだファイルのソースの場所を取得または設定します。

(継承元 XmlSchemaObject)
SubstitutionGroup

この要素で置き換えられる要素の名前を取得または設定します。

UnhandledAttributes

現在のスキーマのターゲット名前空間に属していない修飾属性を取得または設定します。

(継承元 XmlSchemaAnnotated)

メソッド

名前 説明
Equals(Object)

指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象