Megosztás a következőn keresztül:


Séma utáni összeállítási információkészlet

A World Wide Web Consortium (W3C) XML-sémajavaslata a séma előtti ellenőrzéshez és a séma utáni fordításhoz közzéteendő információkészletet (adatkészletet) ismerteti. Az XML-sémaobjektum-modell (SOM) ezt az expozíciót a Compile metódus meghívása előtt és után tekinti XmlSchemaSet meg.

A séma előtti érvényesítési információshalmaz a séma szerkesztése során jön létre. A séma utáni összeállítási információkészlet a metódus meghívása XmlSchemaSet után, a Compile séma összeállítása során jön létre, és tulajdonságokként lesz közzétéve.

Az SOM az az objektummodell, amely a séma előtti érvényesítési és a séma utáni fordítási információkészleteket jelöli; a névtérben lévő System.Xml.Schema osztályokból áll. A névtérben lévő System.Xml.Schema osztályok összes olvasási és írási tulajdonsága a séma előtti érvényesítési információshalmazhoz tartozik, míg a System.Xml.Schema névtérben lévő osztályok írásvédett tulajdonságai a séma utáni összeállítási információskészlethez tartoznak. A szabály alól kivételt képeznek a következő tulajdonságok, amelyek a séma előtti érvényesítési információkészletek és a séma utáni fordítási információshalmaz-tulajdonságok.

Osztály Tulajdonság
XmlSchemaObject Parent
XmlSchema AttributeFormDefault, BlockDefault, ElementFormDefault, FinalDefaultTargetNamespace
XmlSchemaExternal Schema
XmlSchemaAttributeGroup AnyAttribute
XmlSchemaParticle MaxOccurs, MinOccurs
XmlSchemaComplexType AnyAttribute

A két osztály például XmlSchemaElementXmlSchemaComplexType rendelkezik és FinalResolved tulajdonságokkal is rendelkezikBlockResolved. Ezek a tulajdonságok a séma fordítása és ellenőrzése után a tulajdonságok és Final a Block tulajdonságok értékeinek tárolására szolgálnak. BlockResolved és FinalResolved írásvédett tulajdonságok, amelyek a séma utáni összeállítási információhalmaz részét képezik.

Az alábbi példa a ElementSchemaType séma ellenőrzése után az XmlSchemaElement osztálykészlet tulajdonságát mutatja be. Az ellenőrzés előtt a tulajdonság tartalmaz egy null hivatkozást, és a SchemaTypeName tulajdonság a szóban forgó típus nevére van beállítva. Az ellenőrzés után a SchemaTypeName rendszer érvényes típusra oldja fel a problémát, és a típusobjektum a ElementSchemaType tulajdonságon keresztül érhető el.

#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^ eventHandler = gcnew ValidationEventHandler(ValidationCallbackOne);
        schemaSet->ValidationEventHandler += eventHandler;
        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 referred to a valid type.
        Console::WriteLine("After compilation the ElementSchemaType of Price is "
           + priceElem->ElementSchemaType);

    }
};

int main()
{
    PsciSample::Main();
    return 0;
}
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

Lásd még