閱讀英文版本

分享方式:


XmlSchemaInclude 類別

定義

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

C#
public class XmlSchemaInclude : System.Xml.Schema.XmlSchemaExternal
繼承

範例

下列範例會 include 建立 專案。

C#
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

此程式碼範例會產生下列 XML。

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)

適用於

產品 版本
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1