XmlSchemaInclude Kelas

Definisi

include Mewakili elemen dari Skema XML seperti yang ditentukan oleh World Wide Web Consortium (W3C). Kelas ini digunakan untuk menyertakan deklarasi dan definisi dari skema eksternal. Deklarasi dan definisi yang disertakan kemudian tersedia untuk diproses dalam skema yang berisi.

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
Warisan

Contoh

Contoh berikut membuat include elemen .

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

XML berikut dibuat untuk contoh kode ini.

<?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>

Keterangan

Dokumen skema yang disertakan harus memenuhi salah satu kondisi berikut:

Skema yang disertakan harus memiliki namespace layanan target yang sama dengan dokumen skema yang berisi.

OR

Skema yang disertakan tidak boleh memiliki yang ditentukan targetNamespace; targetNamespace atribut harus null.

XmlSchemaInclude menambahkan semua komponen skema dari skema yang disertakan yang memiliki namespace target yang sama (atau tidak ada namespace target yang ditentukan) ke skema yang berisi.

Konstruktor

Nama Deskripsi
XmlSchemaInclude()

Menginisialisasi instans baru dari kelas XmlSchemaInclude.

Properti

Nama Deskripsi
Annotation

Mendapatkan atau mengatur annotation properti.

Id

Mendapatkan atau mengatur id string.

(Diperoleh dari XmlSchemaExternal)
LineNumber

Mendapatkan atau mengatur nomor baris dalam file yang schema dirujuk elemen.

(Diperoleh dari XmlSchemaObject)
LinePosition

Mendapatkan atau mengatur posisi baris dalam file yang schema dirujuk elemen.

(Diperoleh dari XmlSchemaObject)
Namespaces

Mendapatkan atau mengatur XmlSerializerNamespaces untuk digunakan dengan objek skema ini.

(Diperoleh dari XmlSchemaObject)
Parent

Mendapatkan atau mengatur induk dari ini XmlSchemaObject.

(Diperoleh dari XmlSchemaObject)
Schema

Mendapatkan atau mengatur XmlSchema untuk skema yang dirujuk.

(Diperoleh dari XmlSchemaExternal)
SchemaLocation

Mendapatkan atau mengatur lokasi Pengidentifikasi Sumber Daya Seragam (URI) untuk skema, yang memberi tahu prosesor skema tempat skema berada secara fisik.

(Diperoleh dari XmlSchemaExternal)
SourceUri

Mendapatkan atau mengatur lokasi sumber untuk file yang memuat skema.

(Diperoleh dari XmlSchemaObject)
UnhandledAttributes

Mendapatkan atau mengatur atribut yang memenuhi syarat, yang bukan milik namespace target skema.

(Diperoleh dari XmlSchemaExternal)

Metode

Nama Deskripsi
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk