XmlSchemaInclude 類別

定義

將來自 XML 結構描述的 include 項目依 World Wide Web Consortium (W3C) 規定表示。 這個類別 (Class) 用於包含來自外部結構描述的宣告和定義。 然後,所包含的宣告和定義可用於包含結構描述中的處理。

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.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

ref 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 = gcnew XmlSchema();
        schema->ElementFormDefault = XmlSchemaForm::Qualified;
        schema->TargetNamespace = "http://www.w3.org/2001/05/XMLInfoset";

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

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

        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallBack);
        schemaSet->Add(schema);
        schemaSet->Compile();

        XmlSchema^ compiledSchema = nullptr;

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

};

int main()
{
    ImportIncludeSample::Main();
    return 0;
}
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>

備註

包含的架構檔必須符合下列其中一個條件:

包含的架構必須與包含的架構檔具有相同的目標命名空間。

或者

包含的架構不能有指定的 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) 位置,告知結構描述處理器,結構描述實際存放的位置。

(繼承來源 XmlSchemaExternal)
SourceUri

取得或設定載入結構描述之檔案的來源位置。

(繼承來源 XmlSchemaObject)
UnhandledAttributes

取得或設定不屬於結構描述目標命名空間的限定屬性。

(繼承來源 XmlSchemaExternal)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於