Export (0) Print
Expand All

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.

System.Object
   System.Xml.Schema.XmlSchemaObject
      System.Xml.Schema.XmlSchemaExternal
         System.Xml.Schema.XmlSchemaInclude

[Visual Basic]
Public Class XmlSchemaInclude
   Inherits XmlSchemaExternal
[C#]
public class XmlSchemaInclude : XmlSchemaExternal
[C++]
public __gc class XmlSchemaInclude : public XmlSchemaExternal
[JScript]
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.

Remarks

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.

Example

[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: ")
      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)

      
      schema.Compile(AddressOf ValidationCallBack)
      Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(new NameTable())
      nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
      schema.Write(Console.Out, nsmgr)

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

'ImportIncludeSample

[C#] 
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);
                    
        schema.Compile(new ValidationEventHandler(ValidationCallBack)); 
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        schema.Write(Console.Out, nsmgr);
            
    }/* Main() */ 

} //ImportIncludeSample

[C++] 
#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
{
public:
    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"http://www.w3.org/2001/05/XMLInfoset";

    // <xs:import namespace=S"http://www.example.com/IPO" />
    XmlSchemaImport* import = new XmlSchemaImport();
    import -> Namespace = S"http://www.example.com/IPO";
    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"http://www.w3.org/2001/XMLSchema");
    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="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>

[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.

Requirements

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

Show:
© 2015 Microsoft