XmlSchemaInclude Class
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 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.