XmlSchemaInclude Class
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.
Assembly: System.Xml (in System.Xml.dll)
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.
OR
The included schema cannot have a specified targetNamespace; the targetNamespace attribute must be null.
XmlSchemaInclude adds all the schema components from included schemas that have the same target namespace (or no specified target namespace) to the containing schema.
The following example creates the include element.
Imports System 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 'ValidationCallBack 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 'Main End Class 'ImportIncludeSample ' Main() 'ImportIncludeSample
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>
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaExternal
System.Xml.Schema.XmlSchemaInclude
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.