次の方法で共有


スキーマ検証後の情報セット (PSVI)

W3C 勧告『XML Schema』では、スキーマの検証前と検証後に公開する必要のある情報セット (infoset) を扱っています。スキーマ オブジェクト モデル (SOM) は、Compile メソッドが呼び出される前と後にこの公開を表示します。

スキーマの検証前の情報セットは、スキーマの編集時に作成されます。スキーマの検証後の情報セットは、Compile メソッドが呼び出された後の、スキーマのコンパイル時に生成され、プロパティとして公開されます。

SOM は、スキーマの検証の前後の情報セットを表すオブジェクト モデルです。読み取りメソッドと書き込みメソッドの両方を持つプロパティはすべてスキーマの検証前の情報セットに属し、読み取り専用のプロパティはすべてスキーマ検証後の情報セットに属します。

たとえば、XmlSchemaElement クラスと XmlSchemaComplexType クラスは両方とも、BlockResolved プロパティと FinalResolved プロパティを持ちます。これらのプロパティは、スキーマのコンパイルおよび検証後に、Block プロパティと Final プロパティの値を保持するために使用されます。BlockResolved および FinalResolved は、スキーマの検証後の情報セットを構成する読み取り専用プロパティです。

スキーマの検証後に設定される XmlSchemaElement クラスの ElementType プロパティを次の例に示します。検証の前の時点では、このプロパティには null 参照が含まれており、問題のある型の名前に SchemaTypeName が設定されます。検証後は、SchemaTypeName が有効な型に解決され、型オブジェクトは 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

参照

XML スキーマ オブジェクト モデル (SOM)