XmlSchemaInclude クラス

定義

World Wide Web Consortium (W3C) で指定された XML スキーマの include 要素を表します。 このクラスは、外部スキーマからの宣言と定義を含めるために使用されます。 インクルードされた宣言と定義は、包含スキーマで処理できるようになります。

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

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

using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.Schema;

public class ImportIncludeSample
{

    private static void ValidationCallBack(object sender, ValidationEventArgs args)
    {

        if (args.Severity == XmlSeverityType.Warning)
            Console.Write("WARNING: ");
        else if (args.Severity == XmlSeverityType.Error)
            Console.Write("ERROR: ");

        Console.WriteLine(args.Message);
    }

    public static void Main()
    {

        XmlSchema schema = new XmlSchema();
        schema.ElementFormDefault = XmlSchemaForm.Qualified;
        schema.TargetNamespace = "http://www.w3.org/2001/05/XMLInfoset";

        // <xs:import namespace="http://www.example.com/IPO" />
        XmlSchemaImport import = new XmlSchemaImport();
        import.Namespace = "http://www.example.com/IPO";
        schema.Includes.Add(import);

        // <xs:include schemaLocation="example.xsd" />
        XmlSchemaInclude include = new XmlSchemaInclude();
        include.SchemaLocation = "example.xsd";
        schema.Includes.Add(include);

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
        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);
    }/* Main() */
} //ImportIncludeSample
Imports System.Collections
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.Schema


Public Class ImportIncludeSample

    Private Shared Sub ValidationCallBack(ByVal sender As Object, ByVal args As ValidationEventArgs)

        If args.Severity = XmlSeverityType.Warning Then
            Console.Write("WARNING: ")
        Else
            If args.Severity = XmlSeverityType.Error Then
                Console.Write("ERROR: ")
            End If
        End If
        Console.WriteLine(args.Message)
    End Sub


    Public Shared Sub Main()

        Dim schema As New XmlSchema()
        schema.ElementFormDefault = XmlSchemaForm.Qualified
        schema.TargetNamespace = "http://www.w3.org/2001/05/XMLInfoset"

        ' <xs:import namespace="http://www.example.com/IPO" />             
        Dim import As New XmlSchemaImport()
        import.Namespace = "http://www.example.com/IPO"
        schema.Includes.Add(import)

        ' <xs:include schemaLocation="example.xsd" />     
        Dim include As New XmlSchemaInclude()
        include.SchemaLocation = "example.xsd"
        schema.Includes.Add(include)

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

        schemaSet.Add(schema)
        schemaSet.Compile()

        Dim compiledSchema As XmlSchema = Nothing

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

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

    End Sub
End Class

'ImportIncludeSample

このコード例では、次の XML が生成されます。

<?xml version="1.0" encoding="IBM437"?>
<schema elementFormDefault="qualified" targetNamespace="http://www.w3.org/2001/05/XMLInfoset" xmlns="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://www.example.com/IPO" />
  <include schemaLocation="example.xsd" />
</schema>

注釈

含まれるスキーマ ドキュメントは、次のいずれかの条件を満たしている必要があります。

含まれるスキーマには、含まれているスキーマ ドキュメントと同じターゲット名前空間が必要です。

OR

含まれるスキーマには、指定した targetNamespaceを含めることはできません。 targetNamespace 属性は null である必要があります。

XmlSchemaInclude は、同じターゲット名前空間 (または指定されたターゲット名前空間がない) を持つ含まれるスキーマのすべてのスキーマ コンポーネントを、含むスキーマに追加します。

コンストラクター

名前 説明
XmlSchemaInclude()

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

プロパティ

名前 説明
Annotation

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

Id

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

(継承元 XmlSchemaExternal)
LineNumber

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

(継承元 XmlSchemaObject)
LinePosition

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

(継承元 XmlSchemaObject)
Namespaces

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

(継承元 XmlSchemaObject)
Parent

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

(継承元 XmlSchemaObject)
Schema

参照先スキーマの XmlSchema を取得または設定します。

(継承元 XmlSchemaExternal)
SchemaLocation

スキーマの URI (Uniform Resource Identifier) の場所を取得または設定します。これは、スキーマが物理的に存在するスキーマ プロセッサに指示します。

(継承元 XmlSchemaExternal)
SourceUri

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

(継承元 XmlSchemaObject)
UnhandledAttributes

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

(継承元 XmlSchemaExternal)

メソッド

名前 説明
Equals(Object)

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

(継承元 Object)
GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
MemberwiseClone()

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

(継承元 Object)
ToString()

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

(継承元 Object)

適用対象