Dil

Şema sonrası derleme bilgi kümesi

World Wide Web Konsorsiyumu (W3C) XML Şema Önerisi, şema öncesi doğrulama ve şema sonrası derleme için kullanıma sunulmaları gereken bilgi kümesini (infoset) açıklar. XML Şema Nesne Modeli (SOM), Compile yönteminin XmlSchemaSet çağrılmasından önce ve sonra bu durumu görüntüler.

Şema öncesi doğrulama bilgi kümesi, şemanın düzenlenmesi sırasında oluşturulur. Şema sonrası derleme bilgi kümesi, Compile yönteminin XmlSchemaSet üzerinde çağrılmasından sonra, şemanın derlenmesi sırasında oluşturulur ve özellikler olarak kullanıma sunulur.

SOM, şema öncesi doğrulamayı ve şema sonrası derleme bilgi kümelerini temsil eden nesne modelidir; ad alanında System.Xml.Schema sınıflardan oluşur. Ad alanında System.Xml.Schema sınıfların tüm okuma ve yazma özellikleri şema öncesi doğrulama bilgi kümesine aitken, ad alanında System.Xml.Schema sınıfların tüm salt okunur özellikleri şema sonrası derleme bilgi kümesine aittir. Bu kuralın istisnası, hem şema öncesi doğrulama bilgi kümesi hem de şema sonrası derleme bilgi kümesi özellikleri olan aşağıdaki özelliklerdir.

Sınıf Mülkiyet
XmlSchemaObject Parent
XmlSchema AttributeFormDefault, BlockDefault, ElementFormDefault, FinalDefault, , TargetNamespace
XmlSchemaExternal Schema
XmlSchemaAttributeGroup AnyAttribute
XmlSchemaParticle MaxOccurs, MinOccurs
XmlSchemaComplexType AnyAttribute

Örneğin, XmlSchemaElement ve XmlSchemaComplexType sınıflarının her ikisi de BlockResolved ve FinalResolved özelliklerine sahiptir. Bu özellikler, şema derlenip doğrulandıktan sonra Block ve Final özelliklerinin değerlerini tutmak için kullanılır. BlockResolved ve FinalResolved , şema sonrası derleme bilgi kümesinin parçası olan salt okunur özelliklerdir.

Aşağıdaki örnek, şema doğrulandıktan sonra ElementSchemaType sınıfının XmlSchemaElement özelliğinin nasıl ayarlandığını göstermektedir. Doğrulamadan önce özelliği bir null başvuru içerir ve SchemaTypeName söz konusu türün adına ayarlanır. Doğrulamadan sonra, SchemaTypeName geçerli bir türe çözümlenir ve tür nesnesi özelliği aracılığıyla ElementSchemaType kullanılabilir.

using System;
using System.Xml;
using System.Xml.Schema;

public class PsciSample
{
    public static void Main(string[] args)
    {
        XmlSchema schema = new XmlSchema();

        // Create an element of type integer and add it to the schema.
        XmlSchemaElement priceElem = new XmlSchemaElement();
        priceElem.Name = "Price";
        priceElem.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");
        schema.Items.Add(priceElem);

        // Print the pre-compilation value of the ElementSchemaType property
        // of the XmlSchemaElement which is a PSCI property.
        Console.WriteLine("Before compilation the ElementSchemaType of Price is " + priceElem.ElementSchemaType);

        //Compile the schema which validates the schema and
        // if valid will place the PSCI values in certain properties.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += ValidationCallbackOne;
        schemaSet.Add(schema);
        schemaSet.Compile();

        foreach (XmlSchema compiledSchema in schemaSet.Schemas())
        {
            schema = compiledSchema;
        }

        // After compilation of the schema, the ElementSchemaType property of the
        // XmlSchemaElement will contain a reference to a valid object because the
        // SchemaTypeName referred to a valid type.
        Console.WriteLine("After compilation the ElementSchemaType of Price is "
           + priceElem.ElementSchemaType);
    }

    private static void ValidationCallbackOne(object sender, ValidationEventArgs args)
    {
        Console.WriteLine(args.Message);
    }
}
Imports System.Xml
Imports System.Xml.Schema

Public Class PsciSample

    Public Shared Sub Main()

        Dim schema As New XmlSchema()

        ' Create an element of type integer and add it to the schema.
        Dim priceElem As New XmlSchemaElement()
        priceElem.Name = "Price"
        priceElem.SchemaTypeName = New XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema")
        schema.Items.Add(priceElem)

        ' Print the pre-compilation value of the ElementSchemaType property
        ' of the XmlSchemaElement which is a PSCI property.
        Console.WriteLine("Before compilation the ElementSchemaType of Price is {0}", priceElem.ElementSchemaType)

        ' Compile the schema which validates the schema and
        ' if valid will place the PSCI values in certain properties.
        Dim schemaSet As New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne
        schemaSet.Add(schema)
        schemaSet.Compile()

        For Each compiledSchema As XmlSchema In schemaSet.Schemas()
            schema = compiledSchema
        Next

        ' After compilation of the schema, the ElementSchemaType property of the
        ' XmlSchemaElement will contain a reference to a valid object because the
        ' SchemaTypeName referred to a valid type.
        Console.WriteLine("After compilation the ElementSchemaType of Price is {0}", _
                priceElem.ElementSchemaType)

    End Sub

    Private Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub

End Class

Ayrıca bakınız