XmlSchemaValidator.ValidateEndElement XmlSchemaValidator.ValidateEndElement XmlSchemaValidator.ValidateEndElement XmlSchemaValidator.ValidateEndElement Method

定義

単純な内容の要素に対しては、要素のテキストがそのデータ型に従った有効な内容かどうかについて検証し、複雑な内容の要素に対しては、現在の要素の内容が完全かどうかを検証します。Verifies if the text content of the element is valid according to its data type for elements with simple content, and verifies if the content of the current element is complete for elements with complex content.

オーバーロード

ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo)

単純な内容の要素に対しては、要素のテキストがそのデータ型に従った有効な内容かどうかについて検証し、複雑な内容の要素に対しては、現在の要素の内容が完全かどうかを検証します。Verifies if the text content of the element is valid according to its data type for elements with simple content, and verifies if the content of the current element is complete for elements with complex content.

ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object)

指定された要素のテキストが、そのデータ型に従った有効な内容であるかどうかを検証します。Verifies if the text content of the element specified is valid according to its data type.

ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo) ValidateEndElement(XmlSchemaInfo)

単純な内容の要素に対しては、要素のテキストがそのデータ型に従った有効な内容かどうかについて検証し、複雑な内容の要素に対しては、現在の要素の内容が完全かどうかを検証します。Verifies if the text content of the element is valid according to its data type for elements with simple content, and verifies if the content of the current element is complete for elements with complex content.

public:
 System::Object ^ ValidateEndElement(System::Xml::Schema::XmlSchemaInfo ^ schemaInfo);
public object ValidateEndElement (System.Xml.Schema.XmlSchemaInfo schemaInfo);
member this.ValidateEndElement : System.Xml.Schema.XmlSchemaInfo -> obj
Public Function ValidateEndElement (schemaInfo As XmlSchemaInfo) As Object

パラメーター

schemaInfo
XmlSchemaInfo XmlSchemaInfo XmlSchemaInfo XmlSchemaInfo

要素が正常に検証された場合にプロパティが設定される XmlSchemaInfo オブジェクト。An XmlSchemaInfo object whose properties are set on successful validation of the element. このパラメーターは、null に設定できます。This parameter can be null.

戻り値

要素が単純な内容の場合、要素の解析および型指定されたテキスト値。The parsed, typed text value of the element if the element has simple content.

例外

要素の内容が有効ではありません。The element's content is not valid.

ValidateEndElement メソッドは、正しいシーケンスで呼び出されませんでした。The ValidateEndElement method was not called in the correct sequence. たとえば、ValidateEndElement メソッドを呼び出した後で SkipToEndElement(XmlSchemaInfo) メソッドを呼び出した場合が該当します。For example, if the ValidateEndElement method is called after calling SkipToEndElement(XmlSchemaInfo).

注釈

ここでは、 ValidateEndElementメソッドを使用する際に考慮する必要がある重要な注意事項について説明します。The following are important notes to consider when using the ValidateEndElement method.

  • 単純コンテンツを持つ要素の場合ValidateEndElement 、メソッドは、要素のテキストコンテンツがそのデータ型に対して有効であることを検証し、解析された型指定された値を返します。For elements with simple content, the ValidateEndElement method verifies that the text content of the element is valid according to its data type and returns the parsed typed value. 要素のテキストコンテンツは、の前回の呼び出しValidateTextの結果から取得されます。The text content of the element is obtained from the results of previous calls to ValidateText.

  • 複合コンテンツを含む要素の場合ValidateEndElement 、メソッドは、現在の要素の内容が完全であるかどうかを検証します。For elements with complex content, the ValidateEndElement method verifies if the content of the current element is complete.

  • 要素に既定値がある場合、 ValidateEndElementメソッドから返される値は要素の既定値になります。If the element has a default value, the value returned from the ValidateEndElement method is the default value for the element.

  • オブジェクトがパラメーターとしてProcessIdentityConstraints値を使用して構築さValidateEndElementれた場合、メソッドは、要素に適用される id 制約規則 (存在する場合) をチェックします。 XmlSchemaValidatorIf the XmlSchemaValidator object was constructed with the ProcessIdentityConstraints value as a parameter, the ValidateEndElement method checks the identity constraint rules (if any) that apply to the element.

  • XmlSchemaInfo現在のコンテキストで要素が正常に検証されている場合、オブジェクトの (指定されValidityている場合MemberType) IsDefault、、およびの各プロパティは、検証の結果と共に設定されます。If the element is successfully validated in the current context, the XmlSchemaInfo object's (if specified) IsDefault, MemberType, and Validity properties are set with the results of the validation.

こちらもご覧ください

ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object) ValidateEndElement(XmlSchemaInfo, Object)

指定された要素のテキストが、そのデータ型に従った有効な内容であるかどうかを検証します。Verifies if the text content of the element specified is valid according to its data type.

public:
 System::Object ^ ValidateEndElement(System::Xml::Schema::XmlSchemaInfo ^ schemaInfo, System::Object ^ typedValue);
public object ValidateEndElement (System.Xml.Schema.XmlSchemaInfo schemaInfo, object typedValue);
member this.ValidateEndElement : System.Xml.Schema.XmlSchemaInfo * obj -> obj
Public Function ValidateEndElement (schemaInfo As XmlSchemaInfo, typedValue As Object) As Object

パラメーター

schemaInfo
XmlSchemaInfo XmlSchemaInfo XmlSchemaInfo XmlSchemaInfo

要素のテキストの内容が正常に検証された場合にプロパティが設定される XmlSchemaInfo オブジェクト。An XmlSchemaInfo object whose properties are set on successful validation of the text content of the element. このパラメーターは、null に設定できます。This parameter can be null.

typedValue
Object Object Object Object

要素の型指定されたテキストの内容。The typed text content of the element.

戻り値

要素の解析および型指定された単純な内容。The parsed, typed simple content of the element.

例外

要素のテキストの内容が有効ではありません。The element's text content is not valid.

ValidateEndElement メソッドが正しいシーケンスで呼び出されなかった (たとえば、ValidateEndElement が呼び出された後で SkipToEndElement(XmlSchemaInfo) メソッドが呼び出された) か、以前に ValidateText メソッドの呼び出しが行われているか、または要素が複雑な内容です。The ValidateEndElement method was not called in the correct sequence (for example, if the ValidateEndElement method is called after calling SkipToEndElement(XmlSchemaInfo)), calls to the ValidateText method have been previously made, or the element has complex content.

型指定されたテキストの内容のパラメーターは null にできません。The typed text content parameter cannot be null.

次の例ではcontosoBooks.xmlcontosoBooks.xsdスキーマに対してファイルを検証します。The following example validates the contosoBooks.xml file against the contosoBooks.xsd schema. この例では、XmlSerializer クラスを使用して、contosoBooks.xml ファイルを逆シリアル化し、ノードの値を XmlSchemaValidator クラスのメソッドに渡します。The example uses the XmlSerializer class to deserialize the contosoBooks.xml file and pass the value of the nodes to the methods of the XmlSchemaValidator class.

using System;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Collections;

namespace Microsoft.Samples.Xml.Schema
{
    class XmlSchemaValidatorExamples
    {
        static void Main()
        {
            // The XML document to deserialize into the XmlSerializer object.
            XmlReader reader = XmlReader.Create("contosoBooks.xml");

            // The XmlSerializer object.
            XmlSerializer serializer = new XmlSerializer(typeof(ContosoBooks));
            ContosoBooks books = (ContosoBooks)serializer.Deserialize(reader);

            // The XmlSchemaSet object containing the schema used to validate the XML document.
            XmlSchemaSet schemaSet = new XmlSchemaSet();
            schemaSet.Add("http://www.contoso.com/books", "contosoBooks.xsd");

            // The XmlNamespaceManager object used to handle namespaces.
            XmlNamespaceManager manager = new XmlNamespaceManager(reader.NameTable);

            // Assign a ValidationEventHandler to handle schema validation warnings and errors.
            XmlSchemaValidator validator = new XmlSchemaValidator(reader.NameTable, schemaSet, manager, XmlSchemaValidationFlags.None);
            validator.ValidationEventHandler += new ValidationEventHandler(SchemaValidationEventHandler);

            // Initialize the XmlSchemaValidator object.
            validator.Initialize();

            // Validate the bookstore element, verify that all required attributes are present
            // and prepare to validate child content.
            validator.ValidateElement("bookstore", "http://www.contoso.com/books", null);
            validator.GetUnspecifiedDefaultAttributes(new ArrayList());
            validator.ValidateEndOfAttributes(null);

            // Get the next exptected element in the bookstore context.
            XmlSchemaParticle[] particles = validator.GetExpectedParticles();
            XmlSchemaElement nextElement = particles[0] as XmlSchemaElement;
            Console.WriteLine("Expected Element: '{0}'", nextElement.Name);

            foreach (BookType book in books.Book)
            {
                // Validate the book element.
                validator.ValidateElement("book", "http://www.contoso.com/books", null);

                // Get the exptected attributes for the book element.
                Console.Write("\nExpected attributes: ");
                XmlSchemaAttribute[] attributes = validator.GetExpectedAttributes();
                foreach (XmlSchemaAttribute attribute in attributes)
                {
                    Console.Write("'{0}' ", attribute.Name);
                }
                Console.WriteLine();

                // Validate the genre attribute and display its post schema validation information.
                if (book.Genre != null)
                {
                    validator.ValidateAttribute("genre", "", book.Genre, schemaInfo);
                }
                DisplaySchemaInfo();

                // Validate the publicationdate attribute and display its post schema validation information.
                if (book.PublicationDate != null)
                {
                    validator.ValidateAttribute("publicationdate", "", dateTimeGetter(book.PublicationDate), schemaInfo);
                }
                DisplaySchemaInfo();

                // Validate the ISBN attribute and display its post schema validation information.
                if (book.Isbn != null)
                {
                    validator.ValidateAttribute("ISBN", "", book.Isbn, schemaInfo);
                }
                DisplaySchemaInfo();

                // After validating all the attributes for the current element with ValidateAttribute method,
                // you must call GetUnspecifiedDefaultAttributes to validate the default attributes.
                validator.GetUnspecifiedDefaultAttributes(new ArrayList());

                // Verify that all required attributes of the book element are present
                // and prepare to validate child content.
                validator.ValidateEndOfAttributes(null);

                // Validate the title element and its content.
                validator.ValidateElement("title", "http://www.contoso.com/books", null);
                validator.ValidateEndElement(null, book.Title);

                // Validate the author element, verify that all required attributes are present
                // and prepare to validate child content.
                validator.ValidateElement("author", "http://www.contoso.com/books", null);
                validator.GetUnspecifiedDefaultAttributes(new ArrayList());
                validator.ValidateEndOfAttributes(null);

                if (book.Author.Name != null)
                {
                    // Validate the name element and its content.
                    validator.ValidateElement("name", "http://www.contoso.com/books", null);
                    validator.ValidateEndElement(null, book.Author.Name);
                }

                if (book.Author.FirstName != null)
                {
                    // Validate the first-name element and its content.
                    validator.ValidateElement("first-name", "http://www.contoso.com/books", null);
                    validator.ValidateEndElement(null, book.Author.FirstName);

                }

                if (book.Author.LastName != null)
                {
                    // Validate the last-name element and its content.
                    validator.ValidateElement("last-name", "http://www.contoso.com/books", null);
                    validator.ValidateEndElement(null, book.Author.LastName);
                }

                // Validate the content of the author element.
                validator.ValidateEndElement(null);

                // Validate the price element and its content.
                validator.ValidateElement("price", "http://www.contoso.com/books", null);
                validator.ValidateEndElement(null, book.Price);

                // Validate the content of the book element.
                validator.ValidateEndElement(null);
            }

            // Validate the content of the bookstore element.
            validator.ValidateEndElement(null);

            // Close the XmlReader object.
            reader.Close();
        }

        static XmlSchemaInfo schemaInfo = new XmlSchemaInfo();
        static object dateTimeGetterContent;

        static object dateTimeGetterHandle()
        {
            return dateTimeGetterContent;
        }

        static XmlValueGetter dateTimeGetter(DateTime dateTime)
        {
            dateTimeGetterContent = dateTime;
            return new XmlValueGetter(dateTimeGetterHandle);
        }

        static void DisplaySchemaInfo()
        {
            if (schemaInfo.SchemaElement != null)
            {
                Console.WriteLine("Element '{0}' with type '{1}' is '{2}'",
                    schemaInfo.SchemaElement.Name, schemaInfo.SchemaType, schemaInfo.Validity);
            }
            else if (schemaInfo.SchemaAttribute != null)
            {
                Console.WriteLine("Attribute '{0}' with type '{1}' is '{2}'",
                    schemaInfo.SchemaAttribute.Name, schemaInfo.SchemaType, schemaInfo.Validity);
            }
        }

        static void SchemaValidationEventHandler(object sender, ValidationEventArgs e)
        {
            switch (e.Severity)
            {
                case XmlSeverityType.Error:
                    Console.WriteLine("\nError: {0}", e.Message);
                    break;
                case XmlSeverityType.Warning:
                    Console.WriteLine("\nWarning: {0}", e.Message);
                    break;
            }
        }
    }

    [XmlRootAttribute("bookstore", Namespace = "http://www.contoso.com/books", IsNullable = false)]
    public class ContosoBooks
    {
        [XmlElementAttribute("book")]
        public BookType[] Book;
    }

    public class BookType
    {
        [XmlAttributeAttribute("genre")]
        public string Genre;

        [XmlAttributeAttribute("publicationdate", DataType = "date")]
        public DateTime PublicationDate;

        [XmlAttributeAttribute("ISBN")]
        public string Isbn;

        [XmlElementAttribute("title")]
        public string Title;

        [XmlElementAttribute("author")]
        public BookAuthor Author;

        [XmlElementAttribute("price")]
        public Decimal Price;
    }

    public class BookAuthor
    {
        [XmlElementAttribute("name")]
        public string Name;

        [XmlElementAttribute("first-name")]
        public string FirstName;

        [XmlElementAttribute("last-name")]
        public string LastName;
    }
}
Imports System.Xml
Imports System.Xml.Schema
Imports System.Xml.Serialization
Imports System.Collections


Namespace Microsoft.Samples.Xml.Schema

    Class XmlSchemaValidatorExamples

        Shared Sub Main()

            ' The XML document to deserialize into the XmlSerializer object.
            Dim reader As XmlReader = XmlReader.Create("contosoBooks.xml")

            ' The XmlSerializer object.
            Dim serializer As XmlSerializer = New XmlSerializer(GetType(ContosoBooks))
            Dim books As ContosoBooks = CType(serializer.Deserialize(reader), ContosoBooks)

            ' The XmlSchemaSet object containing the schema used to validate the XML document.
            Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
            schemaSet.Add("http://www.contoso.com/books", "contosoBooks.xsd")

            ' The XmlNamespaceManager object used to handle namespaces.
            Dim manager As XmlNamespaceManager = New XmlNamespaceManager(reader.NameTable)

            ' Assign a ValidationEventHandler to handle schema validation warnings and errors.
            Dim validator As XmlSchemaValidator = New XmlSchemaValidator(reader.NameTable, schemaSet, manager, XmlSchemaValidationFlags.None)
            'validator.ValidationEventHandler += New ValidationEventHandler(SchemaValidationEventHandler)
            AddHandler validator.ValidationEventHandler, AddressOf SchemaValidationEventHandler

            ' Initialize the XmlSchemaValidator object.
            validator.Initialize()

            ' Validate the bookstore element, verify that all required attributes are present
            ' and prepare to validate child content.
            validator.ValidateElement("bookstore", "http://www.contoso.com/books", Nothing)

            validator.GetUnspecifiedDefaultAttributes(New ArrayList())
            validator.ValidateEndOfAttributes(Nothing)

            ' Get the next exptected element in the bookstore context.
            Dim particles() As XmlSchemaParticle = validator.GetExpectedParticles()
            Dim nextElement As XmlSchemaElement = particles(0)
            Console.WriteLine("Expected Element: '{0}'", nextElement.Name)

            For Each book As BookType In books.book
                ' Validate the book element.
                validator.ValidateElement("book", "http://www.contoso.com/books", Nothing)

                ' Get the exptected attributes for the book element.
                Console.Write(vbCrLf & "Expected attributes: ")
                Dim attributes() As XmlSchemaAttribute = validator.GetExpectedAttributes()
                For Each attribute As XmlSchemaAttribute In attributes
                    Console.Write("'{0}' ", attribute.Name)
                Next
                Console.WriteLine()

                ' Validate the genre attribute and display its post schema validation information.
                If Not book.Genre Is Nothing Then
                    validator.ValidateAttribute("genre", "", book.Genre, schemaInfo)
                End If
                DisplaySchemaInfo()

                ' Validate the publicationdate attribute and display its post schema validation information.
                If Not book.PublicationDate = Nothing Then
                    validator.ValidateAttribute("publicationdate", "", dateTimeGetter(book.PublicationDate), schemaInfo)
                End If
                DisplaySchemaInfo()

                ' Validate the ISBN attribute and display its post schema validation information.
                If Not book.Isbn Is Nothing Then
                    validator.ValidateAttribute("ISBN", "", book.Isbn, schemaInfo)
                End If
                DisplaySchemaInfo()
    
                ' After validating all the attributes for the current element with ValidateAttribute method,
                ' you must call GetUnspecifiedDefaultAttributes to validate the default attributes.
                validator.GetUnspecifiedDefaultAttributes(New ArrayList())

                ' Verify that all required attributes of the book element are present
                ' and prepare to validate child content.
                validator.ValidateEndOfAttributes(Nothing)

                ' Validate the title element and its content.
                validator.ValidateElement("title", "http://www.contoso.com/books", Nothing)
                validator.ValidateEndElement(Nothing, book.Title)

                ' Validate the author element, verify that all required attributes are present
                ' and prepare to validate child content.
                validator.ValidateElement("author", "http://www.contoso.com/books", Nothing)

                validator.GetUnspecifiedDefaultAttributes(New ArrayList())
                validator.ValidateEndOfAttributes(Nothing)

                If Not book.Author.Name Is Nothing Then
                    ' Validate the name element and its content.
                    validator.ValidateElement("name", "http://www.contoso.com/books", Nothing)
                    validator.ValidateEndElement(Nothing, book.Author.Name)
                End If

                If Not book.Author.FirstName Is Nothing Then
                    ' Validate the first-name element and its content.
                    validator.ValidateElement("first-name", "http://www.contoso.com/books", Nothing)
                    validator.ValidateEndElement(Nothing, book.Author.FirstName)

                End If

                If Not book.Author.LastName Is Nothing Then
                    ' Validate the last-name element and its content.
                    validator.ValidateElement("last-name", "http://www.contoso.com/books", Nothing)
                    validator.ValidateEndElement(Nothing, book.Author.LastName)
                End If

                ' Validate the content of the author element.
                validator.ValidateEndElement(Nothing)

                ' Validate the price element and its content.
                validator.ValidateElement("price", "http://www.contoso.com/books", Nothing)
                validator.ValidateEndElement(Nothing, book.Price)

                ' Validate the content of the book element.
                validator.ValidateEndElement(Nothing)
            Next

            ' Validate the content of the bookstore element.
            validator.ValidateEndElement(Nothing)

            ' Close the XmlReader object.
            reader.Close()

        End Sub

        Shared schemaInfo As XmlSchemaInfo = New XmlSchemaInfo()
        Shared dateTimeGetterContent As Object

        Shared Function dateTimeGetterHandle() As Object

            Return dateTimeGetterContent

        End Function

        Shared Function dateTimeGetter(ByVal dateTime As DateTime) As XmlValueGetter

            dateTimeGetterContent = dateTime
            Return New XmlValueGetter(AddressOf dateTimeGetterHandle)

        End Function

        Shared Sub DisplaySchemaInfo()

            If Not schemaInfo.SchemaElement Is Nothing Then
                Console.WriteLine("Element '{0}' with type '{1}' is '{2}'", schemaInfo.SchemaElement.Name, schemaInfo.SchemaType, schemaInfo.Validity)
            ElseIf Not schemaInfo.SchemaAttribute Is Nothing Then
                Console.WriteLine("Attribute '{0}' with type '{1}' is '{2}'", schemaInfo.SchemaAttribute.Name, schemaInfo.SchemaType, schemaInfo.Validity)
            End If

        End Sub

        Shared Sub SchemaValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs)

            Select Case e.Severity
                Case XmlSeverityType.Error
                    Console.WriteLine(vbCrLf & "Error: {0}", e.Message)
                    Exit Sub
                Case XmlSeverityType.Warning
                    Console.WriteLine(vbCrLf & "Warning: {0}", e.Message)
                    Exit Sub
            End Select

        End Sub

    End Class

    <XmlRootAttribute("bookstore", Namespace:="http://www.contoso.com/books", IsNullable:=False)> _
    Public Class ContosoBooks

        <XmlElementAttribute("book")> _
        Public book() As BookType

    End Class

    Public Class BookType

        <XmlAttributeAttribute("genre")> _
        Public Genre As String

        <XmlAttributeAttribute("publicationdate", DataType:="date")> _
        Public PublicationDate As DateTime

        <XmlAttributeAttribute("ISBN")> _
        Public Isbn As String

        <XmlElementAttribute("title")> _
        Public Title As String

        <XmlElementAttribute("author")> _
        Public Author As BookAuthor

        <XmlElementAttribute("price")> _
        Public Price As Decimal

    End Class

    Public Class BookAuthor

        <XmlElementAttribute("name")> _
        Public Name As String

        <XmlElementAttribute("first-name")> _
        Public FirstName As String

        <XmlElementAttribute("last-name")> _
        Public LastName As String

    End Class

End Namespace

この例は、contosoBooks.xml ファイルを入力として使用します。The example takes the contosoBooks.xml file as input.

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

また、contosoBooks.xsd ファイルも入力として使用します。The example also takes the contosoBooks.xsd as an input.

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="bookstore">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded" name="book">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="title" type="xs:string" />
                            <xs:element name="author">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element minOccurs="0" name="name" type="xs:string" />
                                        <xs:element minOccurs="0" name="first-name" type="xs:string" />
                                        <xs:element minOccurs="0" name="last-name" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="price" type="xs:decimal" />
                        </xs:sequence>
                        <xs:attribute name="genre" type="xs:string" use="required" />
                        <xs:attribute name="publicationdate" type="xs:date" use="required" />
                        <xs:attribute name="ISBN" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

注釈

重要

xs:key ValidateEndElement 、またはxs:uniqueの各 id 制約に対して検証する場合は、メソッドオーバーロードを使用しないでください。 xs:keyrefIf you are validating against the xs:key, xs:keyref, or xs:unique identity constraints, do not use the ValidateEndElement method overload. 代わりに、 ValidateTextメソッドを呼び出して、要素の値を渡します。Instead, call the ValidateText method and pass it the value of the element. 次に、 ValidateEndElement引数としてをXmlSchemaInfo受け取るメソッドオーバーロードを呼び出して、要素のテキストコンテンツがデータ型に従って有効であることを確認します。Then call the ValidateEndElement method overload, which takes XmlSchemaInfo as an argument, to verify that the text content of the element is valid according to its data type.

ここでは、 ValidateEndElementメソッドを使用する際に考慮する必要がある重要な注意事項について説明します。The following are important notes to consider when using the ValidateEndElement method.

  • 単純コンテンツを持つ要素の場合XmlSchemaValidator.ValidateEndElement 、メソッドは、要素のテキストコンテンツがそのデータ型に対して有効であることを検証し、解析された型指定された値を返します。For elements with simple content, the XmlSchemaValidator.ValidateEndElement method verifies that the text content of the element is valid according to its data type and returns the parsed typed value. 要素のテキストコンテンツは、パラメーターとして渡される型指定されたコンテンツから取得されます。The text content of the element is obtained from the typed content passed as a parameter.

  • メソッドのValidateText呼び出しが既に行わInvalidOperationExceptionれている場合は、がスローされます。If calls to the ValidateText method have been previously made, an InvalidOperationException is thrown.

  • 要素に複合コンテンツがある場合InvalidOperationExceptionは、がスローされます。If the element has complex content an InvalidOperationException is thrown.

  • オブジェクトがパラメーターとしてProcessIdentityConstraints値を使用して構築さValidateEndElementれた場合、メソッドは、要素に適用される id 制約規則 (存在する場合) をチェックします。 XmlSchemaValidatorIf the XmlSchemaValidator object was constructed with the ProcessIdentityConstraints value as a parameter, the ValidateEndElement method checks the identity constraint rules (if any) that apply to the element.

  • XmlSchemaInfo現在のコンテキストで要素が正常に検証されている場合、オブジェクトの (指定されValidityている場合MemberType) IsDefault、、およびの各プロパティは、検証の結果と共に設定されます。If the element is successfully validated in the current context, the XmlSchemaInfo object's (if specified) IsDefault, MemberType, and Validity properties are set with the results of the validation.

こちらもご覧ください

適用対象