Freigeben über


Post-Schema-Validation Infoset (PSVI)

Die XML-Schemaempfehlung des W3C (World Wide Web Consortium) erörtert das Infoset, das für Pre- und Post-Schema-Validation offen gelegt werden muss. Das Schemaobjektmodell (SOM) zeigt die Offenlegung vor und nach Aufruf der Compile-Methode an.

Das Pre-Schema-Validation Infoset wird während der Bearbeitung des Schemas erstellt. Das Post-Schema-Validation Infoset wird nach Aufruf der Compile-Methode während der Kompilierung des Schemas generiert und anschließend als Eigenschaften offen gelegt.

Das SOM ist das Objektmodell, das die Pre- und Post-Schema-Validation Infosets repräsentiert. Alle Eigenschaften mit sowohl Lese- als auch Schreibmethoden gehören zum Pre-Schema-Validation Infoset, alle schreibgeschützten Eigenschaften hingegen zum Post-Schema-Validation Infoset.

Beispielsweise verfügen die XmlSchemaElement-Klasse und die XmlSchemaComplexType-Klasse über die BlockResolved-Eigenschaft und die FinalResolved-Eigenschaft. Durch diese Eigenschaften werden die Werte für die Block-Eigenschaft und die Final-Eigenschaft nach Kompilierung und Überprüfung des Schemas beibehalten. Bei BlockResolved und FinalResolved handelt es sich um schreibgeschützte Eigenschaften, die zum Post-Schema-Validation Infoset gehören.

Im folgenden Beispiel wird die ElementType-Eigenschaft des XmlSchemaElement-Klassensets nach Überprüfung des Schemas dargestellt. Vor der Überprüfung enthält die Eigenschaft einen NULL-Verweis, und SchemaTypeName wird auf den Namen des entsprechenden Typs gesetzt. Nach der Überprüfung wird SchemaTypeName in einen gültigen Typ aufgelöst und das Typobjekt durch die ElementType-Eigenschaft verfügbar gemacht.

Imports System.Xml
Imports System.Xml.Schema
Imports System.IO
Imports System

Public Class PsviSample
    
   Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs)
      Console.WriteLine(args.Message)
   End Sub 'ValidationCallbackOne

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 ElementType property 
'   of the XmlSchemaElement which is a PSVI variable.
'     
      'Console.WriteLine("Before compilation the ElementType of Price is " + priceElem.ElementType)
      Console.Write("Before compilation the ElementType of Price is ")
      Console.WriteLine(priceElem.ElementType)
      

' Compile, which validates the schema and, if valid, will place the PSVI 
' values in certain properties.
'      
      schema.Compile(AddressOf ValidationCallbackOne)
      

' After compilation of the schema, the ElementType 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 ElementType of Price is " + priceElem.ElementType)
      Console.Write("After compilation the ElementType of Price is ")
      Console.WriteLine(priceElem.ElementType)
   End Sub ' Main
   
End Class   
' PsviSample
[C#]
using System.Xml; 
using System.Xml.Schema; 
using System.IO;
using System;

public class PsviSample {

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {
   Console.WriteLine(args.Message);
    }

    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 ElementType property 
    of the XmlSchemaElement which is a PSVI variable.
      */
      Console.WriteLine("Before compilation the ElementType of Price is " + priceElem.ElementType );
      
      /* 
    Compile, which validates the schema and, if valid, will place the PSVI 
    values in certain properties. 
      */
      schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); 
      
      /* 
After compilation of the schema, the ElementType 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 ElementType of Price is " 
      + priceElem.ElementType );

    }/* Main(string[]) */

}// PsviSample

Siehe auch

XML-Schemaobjektmodell (SOM)