ValidationEventArgs.Severity プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ValidationEventArgs.Severity プロパティの意味・解説 

ValidationEventArgs.Severity プロパティ

検証イベント重大度レベル取得します

名前空間: System.Xml.Schema
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim instance As ValidationEventArgs
Dim value As XmlSeverityType

value = instance.Severity
public XmlSeverityType Severity { get; }
public:
property XmlSeverityType Severity {
    XmlSeverityType get ();
}
/** @property */
public XmlSeverityType get_Severity ()
public function get Severity
 () : XmlSeverityType

プロパティ
検証イベント重大度レベルを表す XmlSeverityType 値。

使用例使用例

XML ファイル検証して検出されエラーまたは警告生成する例を次に示します

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

Public Class Sample

    Public Shared Sub Main()

        'Load the XmlSchemaSet.
        Dim schemaSet As New
 XmlSchemaSet()
        schemaSet.Add("urn:bookstore-schema", "books.xsd")

        'Validate the file using the schema stored in the schema set.
        'Any elements belonging to the namespace "urn:cd-schema"
 generate
        'a warning because there is no schema matching that namespace.
        Validate("store.xml", schemaSet)

    End Sub

    Shared Sub Validate(ByVal
 filename As String, ByVal
 schemaSet As XmlSchemaSet)

        Console.WriteLine()
        Console.WriteLine("\r\nValidating XML file {0}...",
 filename.ToString())

        Dim compiledSchema As XmlSchema = Nothing

        For Each schema As
 XmlSchema In schemaSet.Schemas()
            compiledSchema = schema
        Next

        Dim settings As New
 XmlReaderSettings()
        settings.Schemas.Add(compiledSchema)
        AddHandler settings.ValidationEventHandler, AddressOf
 ValidationCallBack
        settings.ValidationType = ValidationType.Schema

        'Create the schema validating reader.
        Dim vreader As XmlReader = XmlReader.Create(filename,
 settings)

        While (vreader.Read())

        End While

        'Close the reader.
        vreader.Close()
    End Sub

    'Display any warnings or errors.
    Private Shared Sub ValidationCallBack(ByVal
 sender As Object, ByVal
 args As ValidationEventArgs)
        If (args.Severity = XmlSeverityType.Warning) Then
            Console.WriteLine("  Warning: Matching schema not
 found.  No validation occurred." + args.Message)
        Else
            Console.WriteLine("  Validation error: "
 + args.Message)
        End If
    End Sub

End Class
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Sample
{

    public static void Main()
    {
        //Load the XmlSchemaSet.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.Add("urn:bookstore-schema", "books.xsd");

        //Validate the file using the schema stored in the schema set.
        //Any elements belonging to the namespace "urn:cd-schema"
 generate
        //a warning because there is no schema matching that namespace.
        Validate("store.xml", schemaSet);
        Console.ReadLine();
    }

    private static void
 Validate(String filename, XmlSchemaSet schemaSet)
    {
        Console.WriteLine();
        Console.WriteLine("\r\nValidating XML file {0}...", filename.ToString());

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema in schemaSet.Schemas())
        {
            compiledSchema = schema;
        }

        XmlReaderSettings settings = new XmlReaderSettings();
        settings.Schemas.Add(compiledSchema);
        settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
        settings.ValidationType = ValidationType.Schema;

        //Create the schema validating reader.
        XmlReader vreader = XmlReader.Create(filename, settings);

        while (vreader.Read()) { }

        //Close the reader.
        vreader.Close();
    }

    //Display any warnings or errors.
    private static void
 ValidationCallBack(object sender, ValidationEventArgs args)
    {
        if (args.Severity == XmlSeverityType.Warning)
            Console.WriteLine("\tWarning: Matching schema not found.  No validation
 occurred." + args.Message);
        else
            Console.WriteLine("\tValidation error: " + args.Message);

    }
}

前述の例では、次の入力ファイル使用してます。

store.xml

<?xml version='1.0'?>
<bookstore xmlns="urn:bookstore-schema"
 xmlns:cd="urn:cd-schema">
  <book genre="novel">
    <title>The Confidence
 Man</title>
    <price>11.99</price>
  </book>
  <cd:cd>
    <title>Americana</title>
    <cd:artist>Offspring</cd:artist>
    <price>16.95</price>
  </cd:cd>
</bookstore>

books.xsd

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="urn:bookstore-schema"
    elementFormDefault="qualified"
    targetNamespace="urn:bookstore-schema">

 <xsd:element name="bookstore"
 type="bookstoreType"/>

 <xsd:complexType name="bookstoreType">
  <xsd:sequence maxOccurs="unbounded">
   <xsd:element name="book"
  type="bookType"/>
  </xsd:sequence>
 </xsd:complexType>

 <xsd:complexType name="bookType">
  <xsd:sequence>
   <xsd:element name="title"
 type="xsd:string"/>
   <xsd:element name="author"
 type="authorName"/>
   <xsd:element name="price"
  type="xsd:decimal"/>
  </xsd:sequence>
  <xsd:attribute name="genre"
 type="xsd:string"/>
 </xsd:complexType>

 <xsd:complexType name="authorName">
  <xsd:sequence>
   <xsd:element name="first-name"
  type="xsd:string"/>
   <xsd:element name="last-name"
 type="xsd:string"/>
  </xsd:sequence>
 </xsd:complexType>

</xsd:schema>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ValidationEventArgs クラス
ValidationEventArgs メンバ
System.Xml.Schema 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ValidationEventArgs.Severity プロパティ」の関連用語

ValidationEventArgs.Severity プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ValidationEventArgs.Severity プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS