Share via


Post-Schema-Compilation Infoset

Aktualisiert: November 2007

Im W3C-Dokument XML Schema wird der Informationssatz (Infoset) erörtert, der für die Pre-Schema-Validierung und die Post-Schema-Kompilierung verfügbar gemacht werden muss.Das XML-SOM (Schema Object Model) zeigt dieses Offenlegen vor und nachdem die Compile-Methode vom XmlSchemaSet aufgerufen wird an.

Das Pre-Schema-Validation-Infoset wird während der Bearbeitung des Schemas erstellt. Das Post-Schema-Compilation-Infoset wird nach dem Aufrufen der Compile-Methode vom XmlSchemaSet während der Kompilierung des Schemas erstellt und als Eigenschaften verfügbar gemacht.

Das SOM ist das Objektmodell, das das Pre-Schema-Validation-Infoset und das Post-Schema-Compilation-Infoset darstellt. Es besteht aus den Klassen im System.Xml.Schema-Namespace. Alle Lese- und Schreibeigenschaften der Klassen im System.Xml.Schema-Namespace gehören zum Pre-Schema-Validation-Infoset, während alle schreibgeschützten Eigenschaften der Klassen im System.Xml.Schema-Namespace zum Post-Schema-Compilation-Infoset gehören. Die Ausnahme zu dieser Regel bilden die folgenden Eigenschaften, die sowohl Eigenschaften des Pre-Schema-Validation-Infosets als auch des Post-Schema-Compilation-Infosets sind.

Klasse

Eigenschaft

XmlSchemaObject

Parent

XmlSchema

AttributeFormDefault, BlockDefault, ElementFormDefault, FinalDefault, TargetNamespace

XmlSchemaExternal

Schema

XmlSchemaAttributeGroup

AnyAttribute

XmlSchemaParticle

MaxOccurs, MinOccurs

XmlSchemaComplexType

AnyAttribute

Beispielsweise verfügen die XmlSchemaElement-Klasse und die XmlSchemaComplexType-Klasse beide über die BlockResolved-Eigenschaft und die FinalResolved-Eigenschaft. Diese Eigenschaften enthalten die Werte der Block-Eigenschaft und der Final-Eigenschaft, nachdem das Schema kompiliert und validiert wurde. BlockResolved und FinalResolved sind schreibgeschützte Eigenschaften und Teil des Post-Schema-Compilation-Infosets.

Das folgende Beispiel zeigt die nach dem Validieren des Schemas festgelegte ElementSchemaType-Eigenschaft der XmlSchemaElement-Klasse. Vor der Validierung enthält die Eigenschaft einen null-Verweis, und der SchemaTypeName ist auf den Namen des entsprechenden Typs festgelegt. Nach der Validierung wird der SchemaTypeName in einen gültigen Typ aufgelöst, und das Typobjekt ist über die ElementSchemaType-Eigenschaft verfügbar.

Imports System
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 refered 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
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 refered 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);
    }

}
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

ref class PsciSample
{
private:
    static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)
    {
        Console::WriteLine(args->Message);
    }

public:
    static void Main()
    {
        XmlSchema^ schema = gcnew XmlSchema();

        // Create an element of type integer and add it to the schema.
        XmlSchemaElement^ priceElem = gcnew XmlSchemaElement();
        priceElem->Name = "Price";
        priceElem->SchemaTypeName = gcnew 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 = gcnew XmlSchemaSet();
        ValidationEventHandler^ eventHanlder = gcnew ValidationEventHandler(ValidationCallbackOne);
        schemaSet->ValidationEventHandler += eventHanlder;
        schemaSet->Add(schema);
        schemaSet->Compile();

        for each (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 refered to a valid type.
        Console::WriteLine("After compilation the ElementSchemaType of Price is "
           + priceElem->ElementSchemaType);

    }
};

int main()
{
    PsciSample::Main();
    return 0;
}

Siehe auch

Weitere Ressourcen

XML-Schemaobjektmodell (SOM)