(text sxml object-builder) - SXML to Scheme object builder

Library (text sxml object-builder)

This library provides APIs to build Scheme object from SXML.

High level APIs

Builds a Scheme object from given SXML sxml. The _builder_must be a object-builder described below.

If optional argument unknown-tag-handler is given, then it must be a procedure accepts 2 arguments, builder and sxml. The procedure is called when the process met a tag which can't be handled by given builder. Users can return an object if needed. The default behaviour of the handler is raising an error.

Auxiliary syntax *namespace*
Auxiliary syntax <!>
Auxiliary syntax ?
Auxiliary syntax ??

A DSL which constructs object-builder.

The spec must be one of the followings:

tag can be either a symbol or the following clause:

pred must be a predicate of SXML tag.

ctr must be a procedure which takes 3 arguments, name, attributes and contents. These are SXML's tagname, list of attributes and SXML contents, respectively.

The first form of the spec specifies aliases of namespaces. Users can write qualified name with prefixed instead of unprefixed qualified name.

The second to forth form of spec specify the amount of nested spec ... existence. The * means 0 or more. The + means 1 or more. And the ? means 0 or 1.

The fifth form of spec means cyclic structure.

The sixth form of spec means set of spec spec ....

The following shows how to use this DSL macro

(define builder
  (sxml-object-builder
    (*namespace* ((ns "urn:foo")))
    (ns:bar list
      (ns:buz list)
      (foo list))))

The above definition can build an object from the following SXML

(*TOP*
  (urn:foo:bar
    (urn:foo:buz "buz")
    (foo "foo")))

A generic SXML builder can be written like this:

(define-record-type xml-object
  (fields name attributes contents))

(define xml-object-builder
  (sxml-object-builder
   (<!> (?? values) make-xml-object)))

XML object

This section describes convenience record type and procedures.

Record Type xml-object

A very simple XML object type. An instance of this record type holds tag name (name), attribute as alist (attributes) and contents which must be a valid SXML or other XML objects (contents).

Builds XML object described above from given sxml.