The attributes in schema are defined like child elements. In order to have the attributes the element has a complex type. The only difference is that attributes are not included into sequence/choice scope; rather they are located in complexType-section immediately. The element may contain any number of attribute-definitions:

 <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="">
  <xs:element name="purchase-order">
    <xs:element name="item" maxOccurs="unbounded">
////////////// attributes must be locates in complexType definition:

      <xs:attribute name="code" type="xs:integer"/>

      <xs:attribute name="type">
          <xs:restriction base="xs:string">
            <xs:enumeration value="CD"/>
            <xs:enumeration value="DVD"/>

      <xs:attribute name="label" type="xs:string"/>

Parent Category: Java SE Tips