<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <xs:complexType name="A">
    <xs:sequence>
      <xs:element name="elem" type="B" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute name="foo"/>
  </xs:complexType>

  <xs:complexType name="B">
    <xs:sequence>
      <xs:element name="elem" type="C" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="C">
    <xs:complexContent>
      <xs:restriction base="D">
        <xs:attribute name="foo"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

  <xs:complexType name="D">
    <xs:complexContent>
      <xs:restriction base="A">
        <xs:attribute name="foo"/>
      </xs:restriction>
    </xs:complexContent>
  </xs:complexType>

</xs:schema>