Paul Hoffman

Assignment 3: Schemas

Files

About the XML schema

The XML schema was generated using telf from a source file containing the schema definition (as YAML) and a template (in Template Toolkit form) that defines the overall structure of the generated schema. Auxiliary template files define how the individual bits and pieces of the schema are put together.

Two of the source files are reproduced below for your reading pleasure.

libinfo.xsd

This is the main, ‘driver’ file. It begins with a YAML header containing the schema data, and is followed by the source template. The line containing just ‘...’ separates the two parts of the file. The file has been syntax-colored to make it easier to see what’s what.

---
elements:

  - name: libinfo
    kind: sequence
    description: >-
      Everything you always wanted to know
      about our libraries
    elements:
      - name: library
        kind: sequence
        maxOccurs: unbounded
        description: >-
          A library
        elements:
          - name: name
            kind: simple
            type: xs:string
            description: >-
              The library name
          - name: about
            kind: sequence
            description: >-
              Information about the library
            elements:
              - name: description
                kind: simple
                type: xs:string
                description: >-
                  Description of the library
              - name: address
                kind: sequence
                description: >-
                  The library’s address
                elements:
                  - name: street
                    kind: simple
                    maxOccurs: unbounded
                    type: xs:string
                    description: >-
                      Street and number of the library
                  - name: city
                    kind: simple
                    type: xs:string
                    description: >-
                      City where the library is located
                  - name: state
                    kind: simple
                    type: xs:string
                    description: >-
                      State the library is in
                  - name: postalcode
                    kind: simple
                    type: xs:string
                    description: >-
                      The library's postal code
                  - name: country
                    kind: simple
                    type: xs:string
                    description: >-
                      Country where the library is located
              - name: hours
                kind: sequence
                description: >-
                  The library’s hours
                elements:
                  - name: timespan
                    kind: sequence
                    maxOccurs: unbounded
                    description: >-
                      A span of time during which the library
                      is open
                    elements:
                      - name: day
                        kind: simple
                        type: xs:string
                        description: >-
                          A day when the library is open
                      - name: begin
                        kind: simple
                        type: xs:string
                        description: >-
                          The time at which the library opens
                      - name: end
                        kind: simple
                        type: xs:string
                        description: >-
                          The time at which the library closes
              - name: contact
                kind: simple
                type: xs:string
                description: >-
                  Who to contact for more information
                  about the library
...
<?xml version="1.0" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
[% FILTER indent(2) -%]
[% FOREACH t IN types -%]
[% inc = 'xsd/type/' _ t.kind; INCLUDE $inc self = t -%]
[% END -%]
[% FOREACH e IN elements -%]
[% inc = 'xsd/element/' _ e.kind; INCLUDE $inc self = e -%]
[% END -%]
[% END -%]
</xs:schema>

xsd/element/sequence

This template was actually easier to write (and is easier to read) than the one that determines how xs:simple elements are constructed.

<xs:element name="[% self.name %]"
[%- INCLUDE xsd/element_attributes -%]
>
  <xs:annotation>
    <xs:documentation>
      [% self.description %]
    </xs:documentation>
  </xs:annotation>
  <xs:complexType>
    <xs:sequence>
[% FOREACH e IN self.elements -%]
[% inc = 'xsd/element/' _ e.kind; INCLUDE $inc self = e | indent(6) %]
[% END -%]
    </xs:sequence>
  </xs:complexType>
</xs:element>
About This SiteSite MapPrivacy StatementContact Me ◆ Copyright © 2006 Paul Hoffman ◆ Last modified 2006-04-29 12:02

Valid XHTML 1.0 Transitional Valid CSS!