Condividi tramite


Post-Schema-Validation Infoset (PSVI)

Nella raccomandazione XML Schema del World Wide Web Consortium (W3C) viene illustrato l'insieme di informazioni che è necessario esporre per una convalida pre- e post-schema. Il modello SOM (Schema Object Model) visualizza questa esposizione prima e dopo che venga chiamato il metodo Compile.

L'insieme di informazioni sulla convalida pre-schema viene generato durante la modifica dello schema. L'insieme di informazioni sulla convalida post-schema viene generato dopo la chiamata del metodo Compile durante la compilazione dello schema e viene esposto come proprietà.

Il modello SOM è il modello a oggetti che rappresenta gli insiemi di informazioni sulla convalida pre e post-schema. Tutte le proprietà che hanno sia metodi di lettura che di scrittura appartengono all'insieme di informazioni sulla convalida post-schema.

Le classi XmlSchemaElement e XmlSchemaComplexType, ad esempio, dispongono sia di proprietà BlockResolved che FinalResolved. Esse vengono utilizzate per conservare i valori relativi alle proprietà Block e Final dopo che lo schema è stato compilato e convalidato. BlockResolved e FinalResolved sono proprietà di sola lettura che fanno parte dell'insieme di informazioni sulla convalida post-schema.

Nell'esempio che segue viene illustrata la proprietà ElementType della classe XmlSchemaElement impostata dopo la convalida dello schema. Prima della convalida, la proprietà contiene un riferimento null e lo SchemaTypeName è impostato sul nome del tipo in questione. Dopo la convalida, SchemaTypeName viene risolto in un tipo valido e l'oggetto del tipo è disponibile attraverso la proprietà ElementType.

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

Vedere anche

SOM (Schema Object Model) XML