This documentation is archived and is not being maintained.

XmlSchemaAttribute Class

Attributes provide additional information for other document elements. The attribute tag is nested inbetween the tags of a documents element for the schema. The XML document displays attributes as named item in the opening tag of an element. Represents the World Wide Web Consortium (W3C) attribute element.

For a list of all members of this type, see XmlSchemaAttribute Members.


[Visual Basic]
Public Class XmlSchemaAttribute
   Inherits XmlSchemaAnnotated
public class XmlSchemaAttribute : XmlSchemaAnnotated
public __gc class XmlSchemaAttribute : public XmlSchemaAnnotated
public class XmlSchemaAttribute extends XmlSchemaAnnotated

Thread Safety

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


Attribute declarations can be present as child elements of the schema element (having global scope) or within complex type definitions. For complex types, attribute declarations can be present as local declarations or references to attributes with global scope. Both global and local attribute declarations have the optional type attribute that refers to an existing simple type. If the optional type attribute is not used, the attribute declaration (global or local) must define a local simple type.


[Visual Basic, C#, C++] The following example creates the attribute element.

[Visual Basic] 
Option Explicit
Option Strict

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

Class XMLSchemaExamples
    Public Shared Sub Main()
        Dim schema As New XmlSchema()
        ' <xs:attribute name="mybaseattribute">
        Dim attributeBase As New XmlSchemaAttribute()
        attributeBase.Name = "mybaseattribute"
        ' <xs:simpleType>
        Dim simpleType As New XmlSchemaSimpleType()
        attributeBase.SchemaType = simpleType
        ' <xs:restriction base="integer">
        Dim restriction As New XmlSchemaSimpleTypeRestriction()
        simpleType.Content = restriction
        restriction.BaseTypeName = New XmlQualifiedName("integer", "")
        ' <xs:maxInclusive value="1000"/>
        Dim maxInclusive As New XmlSchemaMaxInclusiveFacet()
        maxInclusive.Value = "1000"
        ' <xs:complexType name="myComplexType">
        Dim complexType As New XmlSchemaComplexType()
        complexType.Name = "myComplexType"
        ' <xs:attribute ref="mybaseattribute"/>
        Dim attributeBaseRef As New XmlSchemaAttribute()
        attributeBaseRef.RefName = New XmlQualifiedName("mybaseattribute")
        schema.Compile(AddressOf ValidationCallbackOne)
        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "")
        schema.Write(Console.Out, nsmgr)
    End Sub 'Main
    Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs)

    End Sub 'ValidationCallbackOne
End Class 'XMLSchemaExamples

using System;
using System.Xml;  
using System.Xml.Schema;

class XMLSchemaExamples {
    public static void Main() {
        XmlSchema schema = new XmlSchema();

        // <xs:attribute name="mybaseattribute">
        XmlSchemaAttribute attributeBase = new XmlSchemaAttribute();
        attributeBase.Name = "mybaseattribute";
        // <xs:simpleType>
        XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
        attributeBase.SchemaType = simpleType;
        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
        simpleType.Content = restriction;
        restriction.BaseTypeName = new XmlQualifiedName("integer", "");
        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
        maxInclusive.Value = "1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        complexType.Name = "myComplexType";
        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute attributeBaseRef = new XmlSchemaAttribute();
        attributeBaseRef.RefName = new XmlQualifiedName("mybaseattribute");
        schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
     XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "");
        schema.Write(Console.Out, nsmgr);

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {


#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;  
using namespace System::Xml::Schema;

__gc class XMLSchemaExamples {
    static void main() {
        XmlSchema* schema = new XmlSchema();

        // <xs:attribute name="mybaseattribute">
        XmlSchemaAttribute* attributeBase = new XmlSchemaAttribute();
        attributeBase->Name = S"mybaseattribute";
        // <xs:simpleType>
        XmlSchemaSimpleType* simpleType = new XmlSchemaSimpleType();
        attributeBase->SchemaType = simpleType;
        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction* restriction = new XmlSchemaSimpleTypeRestriction();
        simpleType->Content = restriction;
        restriction->BaseTypeName = new XmlQualifiedName(S"integer", S"");
        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet* maxInclusive = new XmlSchemaMaxInclusiveFacet();
        maxInclusive->Value = S"1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType* complexType = new XmlSchemaComplexType();
        complexType->Name = S"myComplexType";
        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute* attributeBaseRef = new XmlSchemaAttribute();
        attributeBaseRef->RefName = new XmlQualifiedName(S"mybaseattribute");
        schema->Compile(new ValidationEventHandler(0, ValidationCallbackOne));
     XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr->AddNamespace(S"xs", S"");

    static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) {


int main()

[Visual Basic, C#, C++] The following XML file is generated for the preceding code example.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema  xmlns:xs="">
    <xs:attribute name="mybaseattribute">
            <xs:restriction base="xs:integer">
                <xs:maxInclusive value="1000" />
    <xs:complexType name="myComplexType">
        <xs:attribute ref="mybaseattribute" />

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Xml.Schema

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

XmlSchemaAttribute Members | System.Xml.Schema Namespace