This documentation is archived and is not being maintained.

XmlSchemaAnnotation Class

Represents the World Wide Web Consortium (W3C) annotation element.

Namespace:  System.Xml.Schema
Assembly:  System.Xml (in System.Xml.dll)

public ref class XmlSchemaAnnotation : public XmlSchemaObject

An annotation element can contain one or more XmlSchemaAppInfo instances (information for applications) and XmlSchemaDocumentation instances (comments or text for humans).

An annotation is used to store extra information about the schema or its elements. These notes are specified for human consumption, xs:documentation, or by software, xs:appinfo. Annotation can be the first element of most schema elements or anywhere under the schema element.

The following example creates the annotation element.

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

class XmlSchemaExamples
    static void Main()

        XmlSchema^ schema = gcnew XmlSchema();

        // <xs:simpleType name="northwestStates">
        XmlSchemaSimpleType^ simpleType = gcnew XmlSchemaSimpleType();
        simpleType->Name = "northwestStates";

        // <xs:annotation>
        XmlSchemaAnnotation^ annNorthwestStates = gcnew XmlSchemaAnnotation();
        simpleType->Annotation = annNorthwestStates;

        // <xs:documentation>States in the Pacific Northwest of US</xs:documentation>
        XmlSchemaDocumentation^ docNorthwestStates = gcnew XmlSchemaDocumentation();
        docNorthwestStates->Markup = TextToNodeArray("States in the Pacific Northwest of US");

        // <xs:restriction base="xs:string">
        XmlSchemaSimpleTypeRestriction^ restriction = gcnew XmlSchemaSimpleTypeRestriction();
        simpleType->Content = restriction;
        restriction->BaseTypeName = gcnew XmlQualifiedName("string", "");

        // <xs:enumeration value='WA'>
        XmlSchemaEnumerationFacet^ enumerationWA = gcnew XmlSchemaEnumerationFacet();
        enumerationWA->Value = "WA";

        // <xs:annotation>
        XmlSchemaAnnotation^ annWA = gcnew XmlSchemaAnnotation();
        enumerationWA->Annotation = annWA;

        // <xs:documentation>Washington</documentation>
        XmlSchemaDocumentation^ docWA = gcnew XmlSchemaDocumentation();
        docWA->Markup = TextToNodeArray("Washington");

        // <xs:enumeration value='OR'>
        XmlSchemaEnumerationFacet^ enumerationOR = gcnew XmlSchemaEnumerationFacet();
        enumerationOR->Value = "OR";

        // <xs:annotation>
        XmlSchemaAnnotation^ annOR = gcnew XmlSchemaAnnotation();
        enumerationOR->Annotation = annOR;

        // <xs:documentation>Oregon</xs:documentation>
        XmlSchemaDocumentation^ docOR = gcnew XmlSchemaDocumentation();
        docOR->Markup = TextToNodeArray("Oregon");

        // <xs:enumeration value='ID'>
        XmlSchemaEnumerationFacet^ enumerationID = gcnew XmlSchemaEnumerationFacet();

        enumerationID->Value = "ID";

        // <xs:annotation>
        XmlSchemaAnnotation^ annID = gcnew XmlSchemaAnnotation();
        enumerationID->Annotation = annID;

        // <xs:documentation>Idaho</xs:documentation>
        XmlSchemaDocumentation^ docID = gcnew XmlSchemaDocumentation();
        docID->Markup = TextToNodeArray("Idaho");

        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);

        XmlSchema^ compiledSchema;

        for each (XmlSchema^ schema1 in schemaSet->Schemas())
            compiledSchema = schema1;

        XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable());
        nsmgr->AddNamespace("xs", "");
		compiledSchema->Write(Console::Out, nsmgr);

    static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)

	static array<XmlNode^>^ TextToNodeArray(String^ text)
        XmlDocument^ doc = gcnew XmlDocument();
		array<XmlNode^>^ temp = {doc->CreateTextNode(text)};
        return temp;


int main()
    return 0;

The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="">
    <xs:simpleType name="northwestStates">
        <xs:documentation>States in the Pacific Northwest of US</xs:documentation>
        <xs:restriction base="xs:string">
          <xs:enumeration value='WA'>
          <xs:enumeration value='OR'>
          <xs:enumeration value='ID'>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0