<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- Special types to allow easier processing of Password Safe data -->
<xs:simpleType name="characterType">
  <xs:restriction base="xs:string">
    <xs:length value="1" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="uuidType">
  <xs:restriction base="xs:hexBinary">
    <xs:length value="16" fixed="true"/>
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="stringType">
  <xs:restriction base="xs:string">
    <xs:whiteSpace value="preserve" />
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="datetimestampType">
  <xs:sequence>
    <xs:element name="date" type="xs:date" />
    <xs:element name="time" type="xs:time" />
  </xs:sequence>
</xs:complexType>

<xs:simpleType name="fieldType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="16" />
    <xs:maxExclusive value="255" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="numhashType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="2048" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="fileuuidType">
  <xs:restriction base="xs:string">
    <xs:pattern value="[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA­Z]{12}" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="boolType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="0" />
    <xs:maxInclusive value="1" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="passwordlengthType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="4" />
    <xs:maxInclusive value="1024" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="passwordlengthType2">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="0" />
    <xs:maxInclusive value="1024" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="timeoutType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="1" />
    <xs:maxInclusive value="120" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="displaystatusType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="AllCollapsed" />
    <xs:enumeration value="AllExpanded" />
    <xs:enumeration value="AsPerLastSave" />
  </xs:restriction>
</xs:simpleType>

<xs:simpleType name="pwhistoryType">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="0" />
    <xs:maxInclusive value="255" />
  </xs:restriction>
</xs:simpleType>
<!-- End of Special types -->

<!-- Start of proper Password Safe validation XSD -->
  <xs:element name="passwordsafe">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="NumberHashIterations" type="numhashType" minOccurs="0" maxOccurs="1" />
        <xs:element name="Preferences" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:all>
              <!-- Boolean Database Preferences -->
              <xs:element name="DisplayExpandedAddEditDlg" type="boolType" minOccurs="0" />
              <xs:element name="MaintainDateTimeStamps" type="boolType" minOccurs="0" />
              <xs:element name="PWUseDigits" type="boolType" minOccurs="0" />
              <xs:element name="PWUseEasyVision" type="boolType" minOccurs="0" />
              <xs:element name="PWUseHexDigits" type="boolType" minOccurs="0" />
              <xs:element name="PWUseLowercase" type="boolType" minOccurs="0" />
              <xs:element name="PWUseSymbols" type="boolType" minOccurs="0" />
              <xs:element name="PWUseUppercase" type="boolType" minOccurs="0" />
              <xs:element name="PWMakePronounceable" type="boolType" minOccurs="0" />
              <xs:element name="SaveImmediately" type="boolType" minOccurs="0" />
              <xs:element name="SavePasswordHistory" type="boolType" minOccurs="0" />
              <xs:element name="ShowNotesDefault" type="boolType" minOccurs="0" />
              <xs:element name="ShowPWDefault" type="boolType" minOccurs="0" />
              <xs:element name="ShowPasswordInTree" type="boolType" minOccurs="0" />
              <xs:element name="ShowUsernameInTree" type="boolType" minOccurs="0" />
              <xs:element name="SortAscending" type="boolType" minOccurs="0" />
              <xs:element name="UseDefaultUser" type="boolType" minOccurs="0" />
  
              <!-- Integer Database Preferences -->
              <xs:element name="PWDefaultLength" type="passwordlengthType" minOccurs="0" />
              <xs:element name="IdleTimeout" type="timeoutType" minOccurs="0" />
              <xs:element name="TreeDisplayStatusAtOpen" type="displaystatusType" minOccurs="0" />
              <xs:element name="NumPWHistoryDefault" type="pwhistoryType" minOccurs="0" />
              <xs:element name="PWDigitMinLength" type="passwordlengthType2" minOccurs="0" />
              <xs:element name="PWLowercaseMinLength" type="passwordlengthType2" minOccurs="0" />
              <xs:element name="PWSymbolMinLength" type="passwordlengthType2" minOccurs="0" />
              <xs:element name="PWUppercaseMinLength" type="passwordlengthType2" minOccurs="0" />
  
              <!-- String Database Preferences -->
              <xs:element name="DefaultUsername" type="stringType" minOccurs="0" />
              <xs:element name="DefaultAutotypeString" type="stringType" minOccurs="0" />
            </xs:all>
          </xs:complexType>
        </xs:element>
        <xs:element name="unknownheaderfields" minOccurs="0" maxOccurs="1">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="field" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:simpleContent>
                    <xs:extension base="xs:base64Binary">
                      <xs:attribute name="ftype" type="fieldType" use="required" />
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="entry" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="group" type="stringType" minOccurs="0" maxOccurs="1" />
              <xs:element name="title" type="stringType" />
              <xs:element name="username" type="stringType" minOccurs="0" maxOccurs="1" />
              <xs:element name="password" type="stringType" />
              <xs:element name="url" type="stringType" minOccurs="0" maxOccurs="1" />
              <xs:element name="autotype" type="stringType" minOccurs="0" maxOccurs="1" />
              <xs:element name="notes" type="stringType" minOccurs="0" maxOccurs="1" />
              <xs:element name="uuid" type="uuidType" minOccurs="0" maxOccurs="1" />
              <xs:element name="ctime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
              <xs:element name="atime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
              <xs:element name="ltime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
              <xs:element name="pmtime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
              <xs:element name="rmtime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
              <xs:element name="pwhistory" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="status" type="xs:integer" minOccurs="1" maxOccurs="1" />
                    <xs:element name="max" type="xs:integer" minOccurs="1" maxOccurs="1" />
                    <xs:element name="num" type="xs:integer" minOccurs="1" maxOccurs="1" />
                    <xs:element name="history_entries" minOccurs="0" maxOccurs="1">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="history_entry" minOccurs="0" maxOccurs="255">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="changed" type="datetimestampType" minOccurs="1" maxOccurs="1" />
                                <xs:element name="oldpassword" type="stringType" minOccurs="1" maxOccurs="1" />
                              </xs:sequence>
                              <xs:attribute name="num" type="xs:integer" use="optional" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="PasswordPolicy" minOccurs="0" maxOccurs="1">
                <xs:complexType>
                  <xs:all>
                    <xs:element name="PWLength" type="passwordlengthType" minOccurs="1" maxOccurs="1" />
                    <xs:element name="PWUseDigits" type="boolType" minOccurs="0" />
                    <xs:element name="PWUseEasyVision" type="boolType" minOccurs="0" />
                    <xs:element name="PWUseHexDigits" type="boolType" minOccurs="0" />
                    <xs:element name="PWUseLowercase" type="boolType" minOccurs="0" />
                    <xs:element name="PWUseSymbols" type="boolType" minOccurs="0" />
                    <xs:element name="PWUseUppercase" type="boolType" minOccurs="0" />
                    <xs:element name="PWMakePronounceable" type="boolType" minOccurs="0" />
                    <xs:element name="PWLowercaseMinLength" type="passwordlengthType2" minOccurs="0" />
                    <xs:element name="PWUppercaseMinLength" type="passwordlengthType2" minOccurs="0" />
                    <xs:element name="PWDigitMinLength" type="passwordlengthType2" minOccurs="0" />
                    <xs:element name="PWSymbolMinLength" type="passwordlengthType2" minOccurs="0" />
                  </xs:all>
                </xs:complexType>
              </xs:element>
              <xs:element name="unknownrecordfields" minOccurs="0" maxOccurs="1" >
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="field" minOccurs="0" maxOccurs="unbounded">
                      <xs:complexType>
                        <xs:simpleContent>
                          <xs:extension base="xs:base64Binary">
                            <xs:attribute name="ftype" type="fieldType" use="required" />
                          </xs:extension>
                        </xs:simpleContent>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:integer" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="delimiter" type="characterType" use="required" />
      <xs:attribute name="Database" type="stringType" use="optional" />
      <xs:attribute name="ExportTimeStamp" type="xs:dateTime" use="optional" />
      <xs:attribute name="FromDatabaseFormat" type="stringType" use="optional" />
      <xs:attribute name="WhatSaved" type="stringType" use="optional" />
      <xs:attribute name="WhoSaved" type="stringType" use="optional" />
      <xs:attribute name="WhenLastSaved" type="xs:dateTime" use="optional" />
      <xs:attribute name="Database_uuid" type="fileuuidType" use="optional" />
    </xs:complexType>
  </xs:element>
</xs:schema>
<!-- End of proper Password Safe validation XSD -->
