XmlSchemaInclude 类  
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
按 WWW 联合会 (W3C) 指定的方式显示 include 来自 XML 架构的元素。 此类用于包括来自外部架构的声明和定义。 然后,包括的声明和定义可用于包含架构中的处理。
public ref class XmlSchemaInclude : System::Xml::Schema::XmlSchemaExternalpublic class XmlSchemaInclude : System.Xml.Schema.XmlSchemaExternaltype XmlSchemaInclude = class
    inherit XmlSchemaExternalPublic 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 | 获取或设置  | 
| Id | 获取或设置字符串 ID。(继承自 XmlSchemaExternal) | 
| LineNumber | 获取或设置  | 
| LinePosition | 获取或设置  | 
| Namespaces | 获取或设置用于此架构对象的 XmlSerializerNamespaces。(继承自 XmlSchemaObject) | 
| Parent | 获取或设置此 XmlSchemaObject 的父级。(继承自 XmlSchemaObject) | 
| Schema | 获取或设置所引用架构的  | 
| SchemaLocation | 获取或设置架构的唯一资源标识符 (URI) 位置,该位置告诉架构处理器架构所在的物理位置。(继承自 XmlSchemaExternal) | 
| SourceUri | 获取或设置加载了架构的文件的源位置。(继承自 XmlSchemaObject) | 
| UnhandledAttributes | 获取或设置不属于架构目标命名空间的限定属性。(继承自 XmlSchemaExternal) | 
方法
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |