Per a declarar un atribut amb XML Schema definition utilitzem l'estructura:
<attribute name="x" type="y" />
on l'espai per defecte associat al fitxer XSD és: xmlns="http://www.w3.org/2001/XMLSchema"
En el tipus associat a un atribut, igual com ho fem amb els tipus associats a elements, podem extendre els tipus utilitzats aplicant restriccions als tipus base.
Definició atributs per un element buit
<element name="Order">
<complexType>
<attribute name="OrderID"
type="ID" />
</complexType>
</xs:element>
Definició atributs per un element que conté altres etiquetes
<element name="product" type="tns:tp_product" />
<complexType name="tp_product">
<sequence maxOccurs="unbounded">
<element name="name" type="string" />
<element name="price" type="tns:tp_price" />
<element name="currency" type="tns:tp_currency" />
</sequence>
<attribute name="idproduct" type="ID" />
</complexType>
Definició atributs per un element que conté text
<element name="product" type="tns:tp_product" />
<complexType name="tp_product">
<sequence maxOccurs="unbounded">
<element name="name">
<complexType>
<simpleContent>
<extension base="string">
<attribute name="lang" type="string"/>
</extension>
</simpleContent>
</complexType>
</element>
<element name="price" type="tns:tp_price" />
<element name="currency" type="tns:tp_currency" />
</sequence>
<attribute name="idproduct" type="ID" />
</complexType>
Definició atributs per un element que conté un tipus simple
<?xml version="1.0" encoding="UTF-8" ?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.example.org/exercicis"
targetNamespace="http://www.example.org/exercicis"
elementFormDefault="qualified">
<element name="info">
<complexType>
<sequence>
<element name="nom">
<complexType>
<simpleContent>
<extension base="tns:tp_string">
<attribute name="codi" type="tns:tp_integer" />
</extension>
</simpleContent>
</complexType>
</element>
</sequence>
</complexType>
</element>
<simpleType name="tp_string">
<restriction base="string">
<pattern value="[A-Z][a-z]*"/>
</restriction>
</simpleType>
<simpleType name="tp_integer">
<restriction base="integer">
<minExclusive value="0"/>
</restriction>
</simpleType>
</schema>
Llista completa per tipus atributs: http://www.datypic.com/sc/xsd/s-datatypes.xsd.html