# Class TableSetSaxHandler

java.lang.Object
org.xml.sax.helpers.DefaultHandler
uk.ac.starlink.vo.TableSetSaxHandler

All Implemented Interfaces:
  `ContentHandler, DTDHandler, EntityResolver, ErrorHandler`

public class TableSetSaxHandler extends DefaultHandler
Parses an XML document which describes Tabular Data as prescribed by the VODataService standard. It will pick up <table> elements (of type vs:Table), or elements that look like them, to build a picture of the tables and their columns and foreign keys. XML documents of this type are exposed by VOSI and TAP services.

The easiest way to make use of this class is via the static method `readTableSet(URL, ContentCoding)` or the convenience `main(String[])` method.

See Also:
  - IVOA VODataService Recommendation

## Constructor Summary

Constructors
Constructor
Description
`TableSetSaxHandler()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`characters(char[] ch, int start, int length)`
`void`
`endDocument()`
`void`
`endElement(String uri, String localName, String qName)`
`void`
`endPrefixMapping(String prefix)`
`TableMeta[]`
`getNakedTables()`
Returns the array of table metadata objects which were found outside of any schema.
`SchemaMeta[]`
`getSchemas(boolean includeNaked)`
Returns the array of schema metadata objects which have been read by this parser.
`void`
`ignorableWhitespace(char[] ch, int start, int length)`
`static void`
`main(String[] args)`
Main method to parse a tableset from the command line.
`static TableSetSaxHandler`
`populateHandler(URL url, uk.ac.starlink.util.ContentCoding coding)`
Uses an instance of this class to parse the document at a given URL.
`void`
`processingInstruction(String target, String data)`
`static TableMeta[]`
`readTables(URL url, uk.ac.starlink.util.ContentCoding coding)`
Uses an instance of this class to read an XML document from a given URL and extracts a flat list of all the TableMeta objects it represents.
`static SchemaMeta[]`
`readTableSet(URL url, uk.ac.starlink.util.ContentCoding coding)`
Uses an instance of this class to read an XML document from a given URL and extract the SchemaMeta objects it represents.
`void`
`setDocumentLocator(Locator locator)`
`void`
`skippedEntity(String name)`
`void`
`startDocument()`
`void`
`startElement(String uri, String localName, String qName, Attributes atts)`
`void`
`startPrefixMapping(String prefix, String uri)`

### Methods inherited from class DefaultHandler

`error, fatalError, notationDecl, resolveEntity, unparsedEntityDecl, warning`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface ContentHandler

`declaration`

## Constructor Details

### TableSetSaxHandler

public TableSetSaxHandler()
Constructor.

## Method Details

### getSchemas

public SchemaMeta[] getSchemas(boolean includeNaked)
Returns the array of schema metadata objects which have been read by this parser. Only non-empty following a parse.

Parameters:
  `includeNaked` - if false, only the schemas actually encountered are returned; if true, then any naked tables will be included in a dummy schema in the result
Returns:
  fully populated table metadata

### getNakedTables

public TableMeta[] getNakedTables()
Returns the array of table metadata objects which were found outside of any schema. Only non-empty following a parse.

Returns:
  table metadata

### startDocument

public void startDocument()

Specified by:
  `startDocument` in interface `ContentHandler`
Overrides:
  `startDocument` in class `DefaultHandler`

### endDocument

public void endDocument()

Specified by:
  `endDocument` in interface `ContentHandler`
Overrides:
  `endDocument` in class `DefaultHandler`

### startElement

public void startElement(String uri, String localName, String qName, Attributes atts)

Specified by:
  `startElement` in interface `ContentHandler`
Overrides:
  `startElement` in class `DefaultHandler`

### endElement

public void endElement(String uri, String localName, String qName)

Specified by:
  `endElement` in interface `ContentHandler`
Overrides:
  `endElement` in class `DefaultHandler`

### characters

public void characters(char[] ch, int start, int length)

Specified by:
  `characters` in interface `ContentHandler`
Overrides:
  `characters` in class `DefaultHandler`

### ignorableWhitespace

public void ignorableWhitespace(char[] ch, int start, int length)

Specified by:
  `ignorableWhitespace` in interface `ContentHandler`
Overrides:
  `ignorableWhitespace` in class `DefaultHandler`

### startPrefixMapping

public void startPrefixMapping(String prefix, String uri)

Specified by:
  `startPrefixMapping` in interface `ContentHandler`
Overrides:
  `startPrefixMapping` in class `DefaultHandler`

### endPrefixMapping

public void endPrefixMapping(String prefix)

Specified by:
  `endPrefixMapping` in interface `ContentHandler`
Overrides:
  `endPrefixMapping` in class `DefaultHandler`

### processingInstruction

public void processingInstruction(String target, String data)

Specified by:
  `processingInstruction` in interface `ContentHandler`
Overrides:
  `processingInstruction` in class `DefaultHandler`

### skippedEntity

public void skippedEntity(String name)

Specified by:
  `skippedEntity` in interface `ContentHandler`
Overrides:
  `skippedEntity` in class `DefaultHandler`

### setDocumentLocator

public void setDocumentLocator(Locator locator)

Specified by:
  `setDocumentLocator` in interface `ContentHandler`
Overrides:
  `setDocumentLocator` in class `DefaultHandler`

### readTableSet

public static SchemaMeta[] readTableSet(URL url, uk.ac.starlink.util.ContentCoding coding) throws IOException, SAXException
Uses an instance of this class to read an XML document from a given URL and extract the SchemaMeta objects it represents.

Parameters:
  `url` - containing a TableSet document or similar
  `coding` - configures HTTP content-coding
Returns:
  array of schema metadata objects giving table metadata
Throws:
  `IOException`
  `SAXException`

### readTables

public static TableMeta[] readTables(URL url, uk.ac.starlink.util.ContentCoding coding) throws IOException, SAXException
Uses an instance of this class to read an XML document from a given URL and extracts a flat list of all the TableMeta objects it represents. This includes all the tables in schemas, as well as any outside any `<schema>` element.

Parameters:
  `url` - containing a TableSet document or similar
  `coding` - configures HTTP content-coding
Returns:
  flat list of all tables
Throws:
  `IOException`
  `SAXException`

### populateHandler

public static TableSetSaxHandler populateHandler(URL url, uk.ac.starlink.util.ContentCoding coding) throws IOException, SAXException
Uses an instance of this class to parse the document at a given URL.

Parameters:
  `url` - containing a TableSet document or similar
  `coding` - configures HTTP content-coding
Returns:
  handler containing located items
Throws:
  `IOException`
  `SAXException`

### main

public static void main(String[] args) throws IOException, SAXException
Main method to parse a tableset from the command line.

Parameters:
  `args` - first element is a URL to read from
Throws:
  `IOException`
  `SAXException`