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.
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
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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.