XmlSchema クラス
定義
World Wide Web コンソーシアム (W3C) の『XML スキーマ、パート 1: 構造体』および『XML スキーマ、パート 2: データ型]』で指定されている XML スキーマのメモリ内表現です。An in-memory representation of an XML Schema, as specified in the World Wide Web Consortium (W3C) XML Schema Part 1: Structures and XML Schema Part 2: Datatypes].
public ref class XmlSchema
public ref class XmlSchema : System::Xml::Schema::XmlSchemaObject
public class XmlSchema
public class XmlSchema : System.Xml.Schema.XmlSchemaObject
type XmlSchema = class
type XmlSchema = class
inherit XmlSchemaObject
Public Class XmlSchema
Public Class XmlSchema
Inherits XmlSchemaObject
- 継承
-
XmlSchema
- 継承
例
次の例では、スキーマ定義を作成します。The following example creates a schema definition.
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
class XmlSchemaExamples
{
public:
static void Main()
{
XmlSchema^ schema = gcnew XmlSchema();
// <xs:element name="cat" type="xs:string"/>
XmlSchemaElement^ elementCat = gcnew XmlSchemaElement();
schema->Items->Add(elementCat);
elementCat->Name = "cat";
elementCat->SchemaTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="dog" type="xs:string"/>
XmlSchemaElement^ elementDog = gcnew XmlSchemaElement();
schema->Items->Add(elementDog);
elementDog->Name = "dog";
elementDog->SchemaTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="redDog" substitutionGroup="dog" />
XmlSchemaElement^ elementRedDog = gcnew XmlSchemaElement();
schema->Items->Add(elementRedDog);
elementRedDog->Name = "redDog";
elementRedDog->SubstitutionGroup = gcnew XmlQualifiedName("dog");
// <xs:element name="brownDog" substitutionGroup ="dog" />
XmlSchemaElement^ elementBrownDog = gcnew XmlSchemaElement();
schema->Items->Add(elementBrownDog);
elementBrownDog->Name = "brownDog";
elementBrownDog->SubstitutionGroup = gcnew XmlQualifiedName("dog");
// <xs:element name="pets">
XmlSchemaElement^ elementPets = gcnew XmlSchemaElement();
schema->Items->Add(elementPets);
elementPets->Name = "pets";
// <xs:complexType>
XmlSchemaComplexType^ complexType = gcnew XmlSchemaComplexType();
elementPets->SchemaType = complexType;
// <xs:choice minOccurs="0" maxOccurs="unbounded">
XmlSchemaChoice^ choice = gcnew XmlSchemaChoice();
complexType->Particle = choice;
choice->MinOccurs = 0;
choice->MaxOccursString = "unbounded";
// <xs:element ref="cat"/>
XmlSchemaElement^ catRef = gcnew XmlSchemaElement();
choice->Items->Add(catRef);
catRef->RefName = gcnew XmlQualifiedName("cat");
// <xs:element ref="dog"/>
XmlSchemaElement^ dogRef = gcnew XmlSchemaElement();
choice->Items->Add(dogRef);
dogRef->RefName = gcnew XmlQualifiedName("dog");
XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);
schemaSet->Add(schema);
schemaSet->Compile();
XmlSchema^ compiledSchema;
for each (XmlSchema^ schema1 in schemaSet->Schemas())
{
compiledSchema = schema1;
}
XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable());
nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
compiledSchema->Write(Console::Out, nsmgr);
}
static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)
{
Console::WriteLine(args->Message);
}
};
int main()
{
XmlSchemaExamples::Main();
return 0;
};
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples
{
public static void Main()
{
XmlSchema schema = new XmlSchema();
// <xs:element name="cat" type="xs: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="xs: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);
}
}
Option Explicit On
Option Strict On
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema As New XmlSchema()
' <xs:element name="cat" type="xs: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="xs: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 ファイルが生成されます。The following XML file is generated for the preceding code example.
<?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" type="xs:string" substitutionGroup="dog"/>
<xs:element name="brownDog" type="xs:string" 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>
注釈
重要
- 不明または信頼できないソースまたは場所のスキーマは使用しないでください。Do not use schemas from unknown or untrusted sources or locations. そうすることで、コードのセキュリティが損なわれます。Doing so will compromise the security of your code.
- XML スキーマ (インラインスキーマを含む) は、サービス拒否攻撃に対して本質的に脆弱です。信頼されていないシナリオでは受け入れないでください。XML schemas (including inline schemas) are inherently vulnerable to denial of service attacks; do not accept them in untrusted scenarios.
- クラスなどのクラスを使用した結果として発生した例外には、 XmlSchema XmlSchemaException 信頼されていないシナリオで公開すべきではない機密情報が含まれている場合があります。Exceptions raised as a result of using the XmlSchema class, such as the XmlSchemaException class, may contain sensitive information that should not be exposed in untrusted scenarios. たとえば、 SourceUri のプロパティは、 XmlSchemaException 例外の原因となったスキーマファイルへの URI パスを返します。For example, the SourceUri property of an XmlSchemaException returns the URI path to the schema file that caused the exception. SourceUri信頼されていないシナリオでは、プロパティを公開しないでください。The SourceUri property should not be exposed in untrusted scenarios. 例外は適切に処理する必要があるため、この機密情報は信頼できないシナリオでは公開されません。Exceptions should be properly handled so this sensitive information is not exposed in untrusted scenarios.
コンストラクター
XmlSchema() |
XmlSchema クラスの新しいインスタンスを初期化します。Initializes a new instance of the XmlSchema class. |
フィールド
InstanceNamespace |
XML スキーマ インスタンスの名前空間。The XML schema instance namespace. このフィールドは定数です。This field is constant. |
Namespace |
XML スキーマの名前空間。The XML schema namespace. このフィールドは定数です。This field is constant. |
プロパティ
AttributeFormDefault |
スキーマのターゲット名前空間で宣言された属性の形式を取得または設定します。Gets or sets the form for attributes declared in the target namespace of the schema. |
AttributeGroups |
スキーマ内のすべてのグローバル属性グループについて、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value of all the global attribute groups in the schema. |
Attributes |
スキーマ内のすべての属性について、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value for all the attributes in the schema. |
BlockDefault |
スキーマの |
ElementFormDefault |
スキーマのターゲット名前空間で宣言された要素の形式を取得または設定します。Gets or sets the form for elements declared in the target namespace of the schema. |
Elements |
スキーマ内のすべての要素について、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value for all the elements in the schema. |
FinalDefault |
スキーマのターゲット名前空間の要素および複合型に対し、 |
Groups |
スキーマ内のすべてのグループについて、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value of all the groups in the schema. |
Id |
文字列 ID を取得または設定します。Gets or sets the string ID. |
Includes |
インクルードされたスキーマとインポートされたスキーマのコレクションを取得します。Gets the collection of included and imported schemas. |
IsCompiled |
スキーマがコンパイル済みかどうかを示します。Indicates if the schema has been compiled. |
Items |
スキーマに含まれるスキーマ要素コレクションを取得します。新しい要素型を |
LineNumber |
|
LinePosition |
|
Namespaces |
このスキーマ オブジェクトと一緒に使用する XmlSerializerNamespaces を取得または設定します。Gets or sets the XmlSerializerNamespaces to use with this schema object. (継承元 XmlSchemaObject) |
Notations |
スキーマ内のすべての注釈について、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value for all notations in the schema. |
Parent |
この XmlSchemaObject の親を取得または設定します。Gets or sets the parent of this XmlSchemaObject. (継承元 XmlSchemaObject) |
SchemaTypes |
スキーマ内のすべてのスキーマ型について、スキーマ コンパイル後の値を取得します。Gets the post-schema-compilation value of all schema types in the schema. |
SourceUri |
スキーマを読み込んだファイルのソース位置を取得または設定します。Gets or sets the source location for the file that loaded the schema. (継承元 XmlSchemaObject) |
TargetNamespace |
スキーマのターゲット名前空間の URI (Uniform Resource Identifier) を取得または設定します。Gets or sets the Uniform Resource Identifier (URI) of the schema target namespace. |
UnhandledAttributes |
スキーマのターゲット名前空間に属さない、修飾された属性を取得または設定します。Gets or sets the qualified attributes which do not belong to the schema target namespace. |
Version |
スキーマのバージョンを取得または設定します。Gets or sets the version of the schema. |
メソッド
Compile(ValidationEventHandler) |
互換性のために残されています。
互換性のために残されています。
XML SOM (Schema Object Model) を検証用のスキーマ情報にコンパイルします。Compiles the XML Schema Object Model (SOM) into schema information for validation. プログラムによって構築された SOM の構文および意味構造をチェックするために使用します。Used to check the syntactic and semantic structure of the programmatically built SOM. 意味検証チェックは、コンパイル時に実行されます。Semantic validation checking is performed during compilation. |
Compile(ValidationEventHandler, XmlResolver) |
互換性のために残されています。
互換性のために残されています。
XML SOM (Schema Object Model) を検証用のスキーマ情報にコンパイルします。Compiles the XML Schema Object Model (SOM) into schema information for validation. プログラムによって構築された SOM の構文および意味構造をチェックするために使用します。Used to check the syntactic and semantic structure of the programmatically built SOM. 意味検証チェックは、コンパイル時に実行されます。Semantic validation checking is performed during compilation. |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object. (継承元 Object) |
GetHashCode() |
既定のハッシュ関数として機能します。Serves as the default hash function. (継承元 Object) |
GetType() |
現在のインスタンスの Type を取得します。Gets the Type of the current instance. (継承元 Object) |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object. (継承元 Object) |
Read(Stream, ValidationEventHandler) |
提供されたストリームから XML スキーマを読み込みます。Reads an XML Schema from the supplied stream. |
Read(TextReader, ValidationEventHandler) |
提供された TextReader から XML スキーマを読み込みます。Reads an XML Schema from the supplied TextReader. |
Read(XmlReader, ValidationEventHandler) |
提供された XmlReader から XML スキーマを読み込みます。Reads an XML Schema from the supplied XmlReader. |
ToString() |
現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object. (継承元 Object) |
Write(Stream) |
提供されたデータ ストリームに XML スキーマを書き込みます。Writes the XML Schema to the supplied data stream. |
Write(Stream, XmlNamespaceManager) |
指定された Stream を使用し、指定された XmlNamespaceManager に XML スキーマを書き込みます。Writes the XML Schema to the supplied Stream using the XmlNamespaceManager specified. |
Write(TextWriter) |
提供された TextWriter に XML スキーマを書き込みます。Writes the XML Schema to the supplied TextWriter. |
Write(TextWriter, XmlNamespaceManager) |
提供された TextWriter に XML スキーマを書き込みます。Writes the XML Schema to the supplied TextWriter. |
Write(XmlWriter) |
提供された XmlWriter に XML スキーマを書き込みます。Writes the XML Schema to the supplied XmlWriter. |
Write(XmlWriter, XmlNamespaceManager) |
提供された XmlWriter に XML スキーマを書き込みます。Writes the XML Schema to the supplied XmlWriter. |