An XSD file is itself an XML document. Here is a schema for the library example:

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

  <xs:element name="library">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="book" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="title"  type="xs:string"/>
              <xs:element name="author" type="xs:string"/>
              <xs:element name="year"   type="xs:gYear"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:positiveInteger" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

Validate an XML file against an XSD with xmllint:

xmllint --schema library.xsd --noout library.xml

XSD supports built-in types (xs:string, xs:integer, xs:date, xs:boolean…) and lets you define custom simple types with restrictions such as minimum/maximum values, enumerated values, and regular expression patterns.