Next Previous Up Contents
Next: Table-Aware DOM Processing
Up: Reading VOTables
Previous: Reading VOTables

#### 7.3.1 Generic VOTable Read

The simplest way to read tables from a VOTable document is to use the generic table reading method described in Section 3.2 (or Section 3.3 for streaming) in which you just submit the location of a document to a `StarTableFactory`, and get back one or more `StarTable` objects. If you're after one of several TABLE elements in a document, you can specify this by giving its number as the URL's fragment ID (the bit after the '#' sign, or the third argument of `streamStarTable` for streaming).

The following code would give you `StarTable`s read from the first and fourth TABLE elements in the file "tabledoc.xml":

        StarTableFactory factory = new StarTableFactory();
        StarTable tableA = factory.makeStarTable( "tabledoc.xml", "votable" );
        StarTable tableB = factory.makeStarTable( "tabledoc.xml#3", "votable" );

or equivalently

        VOTableBuilder votBuilder = new VOTableBuilder();
        boolean wantRandom = false;
        StoragePolicy policy = StoragePolicy.getDefaultPolicy();
        StarTable tableA =
            votBuilder.makeStarTable( DataSource.makeDataSource( "tabledoc.xml" ),
                                      wantRandom, policy );
        StarTable tableB =
            votBuilder.makeStarTable( DataSource.makeDataSource( "tabledoc.xml#3" ),
                                      wantRandom, policy );

Note this will perform two separate parses of the document, one for each table built.

If you want all the tables in the document, do this:

        VOTableBuilder votBuilder = new VOTableBuilder();
        DataSource datsrc = DataSource.makeDataSource( "tabledoc.xml" );
        StoragePolicy policy = StoragePolicy.getDefaultPolicy();
        TableSequence tseq = votBuilder.makeStarTables( datsrc, policy );
        List tList = new ArrayList();
        for ( StarTable table; ( table = tseq.nextTable() ) != null; ) {
            tList.add( table );
        }

which only performs a single pass and so is more efficient.

All the data and metadata from the TABLEs in the VOTable document are available from the resulting `StarTable` objects, as table parameters, `ColumnInfo`s or the data themselves. If you are just trying to extract the data and metadata from a single TABLE element somewhere in a VOTable document, this procedure is probably all you need.

Next Previous Up Contents
Next: Table-Aware DOM Processing
Up: Reading VOTables
Previous: Reading VOTables

STIL - Starlink Tables Infrastructure Library
Starlink User Note252
STIL web page: http://www.starlink.ac.uk/stil/
Author email: m.b.taylor@bristol.ac.uk