This documentation is archived and is not being maintained.

XmlSchemaInclude Class

Class to include declarations and definitions from an external schema. Allows them to be available for processing in the containing schema. Represents the World Wide Web Consortium (W3C) include element.

For a list of all members of this type, see XmlSchemaInclude Members.


[Visual Basic]
Public Class XmlSchemaInclude
   Inherits XmlSchemaExternal
public class XmlSchemaInclude : XmlSchemaExternal
public __gc class XmlSchemaInclude : public XmlSchemaExternal
public class XmlSchemaInclude extends XmlSchemaExternal

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


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.


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.


[Visual Basic, C#, C++] The following example creates the include element.

[Visual Basic] 
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(sender As Object, args As ValidationEventArgs)
      If args.Severity = XmlSeverityType.Warning Then
         Console.Write("WARNING: ")
         If args.Severity = XmlSeverityType.Error Then
            Console.Write("ERROR: ")
         End If 
      End If
   End Sub 'ValidationCallBack
   Public Shared Sub Main()
      Dim schema As New XmlSchema()      
      schema.ElementFormDefault = XmlSchemaForm.Qualified      
      schema.TargetNamespace = ""

      ' <xs:import namespace="" />             
      Dim import As New XmlSchemaImport()
      import.Namespace = ""      
      ' <xs:include schemaLocation="example.xsd" />     
      Dim include As New XmlSchemaInclude()
      include.SchemaLocation = "example.xsd"      

      schema.Compile(AddressOf ValidationCallBack)
      Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(new NameTable())
      nsmgr.AddNamespace("xs", "")
      schema.Write(Console.Out, nsmgr)

   End Sub 'Main 
End Class 'ImportIncludeSample ' Main() 


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: ");
    public static void Main() {
        XmlSchema schema = new XmlSchema();         
        schema.ElementFormDefault = XmlSchemaForm.Qualified;
        schema.TargetNamespace = "";
        // <xs:import namespace="" />                            
        XmlSchemaImport import = new XmlSchemaImport();
        import.Namespace = "";       
        // <xs:include schemaLocation="example.xsd" />               
        XmlSchemaInclude include = new XmlSchemaInclude();
        include.SchemaLocation = "example.xsd";        
        schema.Compile(new ValidationEventHandler(ValidationCallBack)); 
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "");
        schema.Write(Console.Out, nsmgr);
    }/* Main() */ 

} //ImportIncludeSample

#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Xsl;
using namespace System::Xml::Schema;

__gc public class ImportIncludeSample
    static void ValidationCallBack(Object* /*sender*/, ValidationEventArgs * args)
        if (args -> Severity == XmlSeverityType::Warning)
            Console::Write(S"WARNING: ");
        else if (args -> Severity == XmlSeverityType::Error)
            Console::Write(S"ERROR: ");
        Console::WriteLine(args -> Message);
}; // ImportIncludeSample

int main()
    XmlSchema* schema = new XmlSchema();
    schema -> ElementFormDefault = XmlSchemaForm::Qualified;
    schema -> TargetNamespace = S"";

    // <xs:import namespace=S"" />
    XmlSchemaImport* import = new XmlSchemaImport();
    import -> Namespace = S"";
    schema -> Includes->Add(import);

    // <xs:include schemaLocation=S"example.xsd" />
    XmlSchemaInclude* include = new XmlSchemaInclude();
    include -> SchemaLocation = S"example.xsd";
    schema -> Includes->Add(include);

    schema -> Compile(new ValidationEventHandler(schema, ImportIncludeSample::ValidationCallBack));
    XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
    nsmgr -> AddNamespace(S"xs", S"");
    schema -> Write(Console::Out, nsmgr);
}  // main

[Visual Basic, C#, C++] The following XML is generated for this code example.

<?xml version="1.0" encoding="IBM437"?>
<schema elementFormDefault="qualified" targetNamespace="" xmlns="">
  <import namespace="" />
  <include schemaLocation="example.xsd" />

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Xml (in System.Xml.dll)

See Also

XmlSchemaInclude Members | System.Xml.Schema Namespace