XmlSchemaInclude 类
定义
按 WWW 联合会 (W3C) 指定的方式显示 include 来自 XML 架构的元素。Represents the include element from XML Schema as specified by the World Wide Web Consortium (W3C). 此类用于包括来自外部架构的声明和定义。This class is used to include declarations and definitions from an external schema. 然后,包括的声明和定义可用于包含架构中的处理。The included declarations and definitions are then available for processing in the containing schema.
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 元素。The following example creates the include element.
#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。The following XML is generated for this code example.
<?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>
注解
包含的架构文档必须满足以下条件之一:The included schema document must meet one of the following conditions:
包含的架构必须与包含架构文档具有相同的目标命名空间。The included schema must have the same target namespace as the containing schema document.
OROR
包含的架构不能具有指定的 targetNamespace ; targetNamespace 特性必须为 null。The included schema cannot have a specified targetNamespace; the targetNamespace attribute must be null.
XmlSchemaInclude 将具有相同目标命名空间 (或没有指定目标命名空间) 的包含架构中的所有架构组件添加到包含架构。XmlSchemaInclude adds all the schema components from included schemas that have the same target namespace (or no specified target namespace) to the containing schema.
构造函数
| XmlSchemaInclude() |
初始化 XmlSchemaInclude 类的新实例。Initializes a new instance of the XmlSchemaInclude class. |
属性
| Annotation |
获取或设置 |
| Id |
获取或设置字符串 ID。Gets or sets the string id. (继承自 XmlSchemaExternal) |
| LineNumber |
获取或设置 |
| LinePosition |
获取或设置 |
| Namespaces |
获取或设置用于此架构对象的 XmlSerializerNamespaces。Gets or sets the XmlSerializerNamespaces to use with this schema object. (继承自 XmlSchemaObject) |
| Parent |
获取或设置此 XmlSchemaObject 的父级。Gets or sets the parent of this XmlSchemaObject. (继承自 XmlSchemaObject) |
| Schema |
获取或设置所引用架构的 |
| SchemaLocation |
获取或设置架构的唯一资源标识符 (URI) 位置,该位置告诉架构处理器架构所在的物理位置。Gets or sets the Uniform Resource Identifier (URI) location for the schema, which tells the schema processor where the schema physically resides. (继承自 XmlSchemaExternal) |
| SourceUri |
获取或设置加载了架构的文件的源位置。Gets or sets the source location for the file that loaded the schema. (继承自 XmlSchemaObject) |
| UnhandledAttributes |
获取或设置不属于架构目标命名空间的限定属性。Gets or sets the qualified attributes, which do not belong to the schema target namespace. (继承自 XmlSchemaExternal) |
方法
| 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) |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |