[prev] [up] [next]

XML Object Storage

Contents

Introduction

This document will teach you how to store and retrieve objects on/from an external medium in XML format.

Smalltalk offers various ways to store and retrieve objects to/from the external world. For textual storage of non-recursive objects, you can also use the well-known #storeOn: / #readFrom: methods. For a very compact binary encoding of arbitrary object hierarchies (can be recursive), you would use #storeBinaryOn: / #readBinaryFrom:.

Both of the above are described in "Binary Object Storage".

XML storage as described here allows for other XML tools to interact more easily with Smalltalk storage files.

Default Storage Format

The default format is already impleemnted and supported for all objects. SO, to make your objects persistent, you don't have to write any code. However, the resulting storage format (the dtd) is pretty much streamlined towards Smalltalk, and reading/writing it from non-smalltalk systems may be a bit harder.

The scheme writes all named and indexed instance variables. Unassigned slots (nil-valued) are skipped.
For example:

    |myObject outStream|

    myObject := Array with:'hello world'
		      with:1.2345
		      with:#(1 2 3 4 5)
		      with:('ne' -> #one)
		      with:nil.
    myObject at:5 put:myObject.

    outStream := 'data.xml' asFilename writeStream.

    (XMLStandardCoder on:outStream) nextPut:myObject.

    outStream close.
generates a datafile containing a representation of the stored array.

From this, the object can be reconstructed:

    |restoredObject|

    restoredObject := (XMLStandardDecoder on:('data.xml' asFilename readStream)) next.
    restoredObject inspect.

Other XML Schemas

At the time of writing, support for other formats can be implemented by one of two strategies: Of course, specific xml-writer methods are required independent of how the reader is implemented.

We are working on a scheme which is both easy to use and flexible enough to support a wide range of formats.

[... expect more to come soon...]


Copyright © 2008 eXept Software AG

<cg at exept.de>

Doc $Revision: 1.6 $ $Date: 2021/03/13 18:24:52 $