XmlSchemaInclude Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Representerar elementet include från XML-schema enligt vad som anges av World Wide Web Consortium (W3C). Den här klassen används för att inkludera deklarationer och definitioner från ett externt schema. De inkluderade deklarationerna och definitionerna är sedan tillgängliga för bearbetning i det innehållande schemat.
public ref class XmlSchemaInclude : System::Xml::Schema::XmlSchemaExternal
public class XmlSchemaInclude : System.Xml.Schema.XmlSchemaExternal
type XmlSchemaInclude = class
inherit XmlSchemaExternal
Public Class XmlSchemaInclude
Inherits XmlSchemaExternal
- Arv
Exempel
I följande exempel skapas elementet include .
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
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
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
End Class
'ImportIncludeSample
Följande XML genereras för det här kodexemplet.
<?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>
Kommentarer
Det inkluderade schemadokumentet måste uppfylla något av följande villkor:
Det inkluderade schemat måste ha samma målnamnområde som det innehållande schemadokumentet.
ELLER
Det inkluderade schemat kan inte ha ett angivet targetNamespace. targetNamespace Attributet måste vara null.
XmlSchemaInclude lägger till alla schemakomponenter från inkluderade scheman som har samma målnamnområde (eller inget angivet målnamnområde) i det innehållande schemat.
Konstruktorer
| Name | Description |
|---|---|
| XmlSchemaInclude() |
Initierar en ny instans av XmlSchemaInclude klassen. |
Egenskaper
| Name | Description |
|---|---|
| Annotation |
Hämtar eller anger egenskapen |
| Id |
Hämtar eller anger sträng-ID: t. (Ärvd från XmlSchemaExternal) |
| LineNumber |
Hämtar eller anger radnumret i filen som elementet |
| LinePosition |
Hämtar eller anger radpositionen i filen som elementet |
| Namespaces |
Hämtar eller anger det XmlSerializerNamespaces som ska användas med det här schemaobjektet. (Ärvd från XmlSchemaObject) |
| Parent |
Hämtar eller anger överordnad för den här XmlSchemaObject. (Ärvd från XmlSchemaObject) |
| Schema |
Hämtar eller anger |
| SchemaLocation |
Hämtar eller anger URI-platsen (Uniform Resource Identifier) för schemat, som talar om för schemaprocessorn var schemat finns fysiskt. (Ärvd från XmlSchemaExternal) |
| SourceUri |
Hämtar eller anger källplatsen för filen som läste in schemat. (Ärvd från XmlSchemaObject) |
| UnhandledAttributes |
Hämtar eller anger de kvalificerade attributen, som inte tillhör schemats målnamnområde. (Ärvd från XmlSchemaExternal) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar det aktuella objektet. (Ärvd från Object) |