This documentation is archived and is not being maintained.

XmlSchemaAttributeGroup Class

Represents the attributeGroup element from the XML Schema as specified by the World Wide Web Consortium (W3C). AttributesGroups provides a mechanism to group a set of attribute declarations so that they can be incorporated as a group into complex type definitions.

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

public class XmlSchemaAttributeGroup : XmlSchemaAnnotated

An attribute group can be defined only as a child of the schema element. In this case, the name attribute must be present and contain the attribute, attributeGroup, or anyAttribute elements that make up the attribute group. When a complexType or an attributeGroup element includes an attribute group, the ref attribute must be present and the name attribute is not allowed.

The following example creates the attributeGroup element.

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

class XMLSchemaExamples
    public static void Main()

        XmlSchema schema = new XmlSchema();

        // <xs:attributeGroup name="myAttributeGroup">
        XmlSchemaAttributeGroup myAttributeGroup = new XmlSchemaAttributeGroup();
        myAttributeGroup.Name = "myAttributeGroup";

        // <xs:attribute name="someattribute1" type="xs:integer"/>
        XmlSchemaAttribute someattribute1 = new XmlSchemaAttribute();
        someattribute1.Name = "someattribute1";
        someattribute1.SchemaTypeName = new XmlQualifiedName("integer", "");

        // <xs:attribute name="someattribute2" type="xs:string"/>
        XmlSchemaAttribute someattribute2 = new XmlSchemaAttribute();
        someattribute2.Name = "someattribute2";
        someattribute2.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:complexType name="myElementType">
        XmlSchemaComplexType myElementType = new XmlSchemaComplexType();
        myElementType.Name = "myElementType";

        // <xs:attributeGroup ref="myAttributeGroup"/>
        XmlSchemaAttributeGroupRef myAttributeGroupRef = new XmlSchemaAttributeGroupRef();
        myAttributeGroupRef.RefName = new XmlQualifiedName("myAttributeGroup");

        // <xs:attributeGroup name="myAttributeGroupA">
        XmlSchemaAttributeGroup myAttributeGroupA = new XmlSchemaAttributeGroup();
        myAttributeGroupA.Name = "myAttributeGroupA";

        // <xs:attribute name="someattribute10" type="xs:integer"/>
        XmlSchemaAttribute someattribute10 = new XmlSchemaAttribute();
        someattribute10.Name = "someattribute10";
        someattribute10.SchemaTypeName = new XmlQualifiedName("integer", "");

        // <xs:attribute name="someattribute11" type="xs:string"/>
        XmlSchemaAttribute someattribute11 = new XmlSchemaAttribute();
        someattribute11.Name = "someattribute11";
        someattribute11.SchemaTypeName = new XmlQualifiedName("string", "");

        // <xs:attributeGroup name="myAttributeGroupB">
        XmlSchemaAttributeGroup myAttributeGroupB = new XmlSchemaAttributeGroup();
        myAttributeGroupB.Name = "myAttributeGroupB";

        // <xs:attribute name="someattribute20" type="xs:date"/>
        XmlSchemaAttribute someattribute20 = new XmlSchemaAttribute();
        someattribute20.Name = "someattribute20";
        someattribute20.SchemaTypeName = new XmlQualifiedName("date", "");

        // <xs:attributeGroup ref="myAttributeGroupA"/>
        XmlSchemaAttributeGroupRef myAttributeGroupRefA = new XmlSchemaAttributeGroupRef();
        myAttributeGroupRefA.RefName = new XmlQualifiedName("myAttributeGroupA");

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
            compiledSchema = schema1;

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "");
        compiledSchema.Write(Console.Out, nsmgr);

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)


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

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="">
    <xs:attributeGroup name="myAttributeGroup">
        <xs:attribute name="someattribute1" type="xs:integer"/>
        <xs:attribute name="someattribute2" type="xs:string"/>

    <xs:complexType name="myElementType">
        <xs:attributeGroup ref="myAttributeGroup"/>

    <xs:attributeGroup name="myAttributeGroupA">
        <xs:attribute name="someattribute10" type="xs:integer"/>
        <xs:attribute name="someattribute11" type="xs:string"/>

    <xs:attributeGroup name="myAttributeGroupB">
        <xs:attribute name="someattribute20" type="xs:date"/>
        <xs:attributeGroup ref="myAttributeGroupA"/>

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