### 18 Storing AST Objects as XML (XmlChan)

18.1 Reading IVOA Space-Time-Coordinates XML (STC-X) Descriptions

XML 35 is fast becoming the standard format for passing structured data around the internet, and much general purpose software has been written for tasks such as the parsing, editing, display and transformation of XML data. The XmlChan class (a specialised form of Channel) provides facilities for storing AST objects externally in the form of XML documents, thus allowing such software to be used.

The primary XML format used by the XmlChan class is a fairly close transliteration of the AST native format produced by the basic Channel class. Currently, there is no DTD or schema defining the structure of data produced in this format by an XmlChan. The following is a native AST representation of a simple 1-D Frame (including comments and with the Full attribute set to zero so that some default attribute values are included as extra comments):

Begin Frame # Coordinate system description
# Title = "1-d coordinate system" # Title of coordinate system
Naxes = 1 # Number of coordinate axes
Domain = "SCREEN" # Coordinate system domain
# Lbl1 = "Axis 1" # Label for axis 1
# Uni1 = "cm" # Units for axis 1
Ax1 = # Axis number 1
Begin Axis # Coordinate axis
Unit = "cm" # Axis units
End Axis
End Frame

The corresponding XmlChan output would look like:

<Frame xmlns="http://www.starlink.ac.uk/ast/xml/"
desc="Coordinate system description">
<_attribute name="Title" quoted="true" value="1-d coordinate system"
desc="Title of coordinate system" default="true"/>
<_attribute name="Naxes" value="1" desc="Number of coordinate axes"/>
<_attribute name="Domain" quoted="true" value="SCREEN"
desc="Coordinate system domain"/>
<_attribute name="Lbl1" quoted="true" value="Axis 1"
desc="Label for axis 1" default="true"/>
<_attribute name="Uni1" quoted="true" value="cm"
desc="Units for axis 1" default="true"/>
<Axis label="Ax1" desc="Coordinate axis">
<!--Axis number 1-->
<_attribute name="Unit" quoted="true" value="cm" desc="Axis units"/>
</Axis>
</Frame>

Notes:

(1)
  The AST class name is used as the name for an XML element which contain a description of an AST object.
(2)
  AST attributes are described by XML elements with the name “_attribute”. Unfortunately, the word “attribute” is also used by XML to refer to a “name=value” pair within an element start tag. So for instance, the “Title” attribute of the AST Frame object is described within an XML element with name “_attribute” in which the XML attribute “name” has the value “Title”, and the XML attribute “value” has the value “1-d coordinate system”. The moral is always to be clear clear about the context (AST or XML) in which the word attribute is being used!
(3)
  The XML includes comments both as XML attributes with the name “desc”, and as separate comment tags.
(4)
  Elements which describe default values are identified by the fact that they have an XML attribute called “default” set to the value “true”. These elements are ignored when being read back into an XmlChan.
(5)
  The outer-most XML element of an AST object will set the default namespace to http://www.starlink.ac.uk/ast/xml/ which will be inherited by all nested elements.

The XmlChan class changes the default value for the Comment and Full attributes (inherited from the base Channel class) to zero and -1, resulting in terse output by default. With the default values for these attributes, the above XML is reduced to the following:

<Frame xmlns="http://www.starlink.ac.uk/ast/xml/">
<_attribute name="Naxes" value="1"/>
<_attribute name="Domain" quoted="true" value="SCREEN"/>
<Axis label="Ax1">
<_attribute name="Unit" quoted="true" value="cm"/>
</Axis>
</Frame>

The XmlChan class uses the Skip attributes very similarly to the Channel class. If Skip is zero (the default) then an error will be reported if the text supplied by the source function does not begin with an AST Object. If Skip is non-zero, then initial text is skipped over without error until the start of an AST object is found. this allows an AST object to be located within a larger XML document.

#### 18.1 Reading IVOA Space-Time-Coordinates XML (STC-X) Descriptions

The XmlChan class also provides support for reading (but not writing) XML documents which use a restricted subset of an early draft (V1.20) of the IVOA Space-Time-Coordinates XML (STC-X) system. The version of STC-X finally adopted by the IVOA differs in several significant respects from V1.20, and so the STC-X support currently provided by AST is mainly of historical interest. Note, AST also supports the alternative “STC-S” linear string description of the STC model (see §19).

STC-X V1.20 is documented at http://www.ivoa.net/Documents/WD/STC/STC-20050225.html, and the current version is documented at http://www.ivoa.net/Documents/latest/STC-X.html.

When an STC-X document is read using an XmlChan, the read operation produces an AST Object of the Stc class, which is itself a subclass of Region. Specifically, each such Object will be an instance of StcSearchLocation, StcResourceProfile, StcCatalogEntryLocation or StcObsDataLocation. See the description of the XmlChan class and the XmlFormat attribute for further details.

35http://www.w3.org/XML/

Copyright (C) 2021 East Asian Observatory