Infoset voor compilatie na schema
In de aanbeveling voor het W3C-schema (World Wide Web Consortium) wordt de informatieset (infoset) besproken die moet worden weergegeven voor pre-schemavalidatie en post-schemacompilatie. Het XML Schema Object Model (SOM) bekijkt deze blootstelling voor en nadat de methode van de CompileXmlSchemaSet aangeroepen methode is aangeroepen.
De infoset voor validatie van het preschema wordt gebouwd tijdens het bewerken van het schema. De compilatiegegevensset na het schema wordt gegenereerd nadat de Compile methode van de XmlSchemaSet aangeroepen methode, tijdens de compilatie van het schema, wordt weergegeven als eigenschappen.
De SOM is het objectmodel dat de pre-schemavalidatie en compilatiegegevenssets na het schema vertegenwoordigt; deze bestaat uit de klassen in de System.Xml.Schema naamruimte. Alle eigenschappen voor lezen en schrijven van klassen in de System.Xml.Schema naamruimte behoren tot de infoset voor validatie van het preschema, terwijl alle alleen-lezen eigenschappen van klassen in de System.Xml.Schema naamruimte deel uitmaken van de infoset van de compilatie na het schema. De uitzondering op deze regel zijn de volgende eigenschappen, die zowel infoset van preschemavalidatie als infoset na schemacompilatie zijn.
De klassen XmlSchemaComplexType hebben BlockResolved
bijvoorbeeld XmlSchemaElement zowel eigenschappen als FinalResolved
eigenschappen. Deze eigenschappen worden gebruikt om de waarden voor de Block
en Final
eigenschappen op te slaan nadat het schema is gecompileerd en gevalideerd. BlockResolved
en FinalResolved
alleen-lezen eigenschappen zijn die deel uitmaken van de compilatiegegevensset na het schema.
In het volgende voorbeeld ziet u de ElementSchemaType eigenschap van de XmlSchemaElement klassenset na het valideren van het schema. Voordat de validatie wordt uitgevoerd, bevat de eigenschap een null
verwijzing en wordt deze SchemaTypeName ingesteld op de naam van het betreffende type. Na validatie wordt het SchemaTypeName omgezet in een geldig type en is het typeobject beschikbaar via de ElementSchemaType eigenschap.
#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