Science With the Virtual Observatory
2006 Summer School

XML Technologies -- Examples and Exercises

The exercises presented here are companions to the presentation XML Technologies (PDF, PPT).

In this presentation, we'll be using some tools from the ADQL library that comes with in your summer school software package. To build them, change into the adqllib package directory and run ant:

on Linux/MacOS:
cd $NVOSS_HOME/java/src/adqllib
ant
   on Windows:
cd %NVOSS_HOME%\java\src\adqllib
ant

25 seconds or so later, you should see ant print "BUILD SUCCESSFUL" to the screen. If you are Linux or MacOS, you might want to type rehash to ensure the new tools are available to you.

Part 1: XML Schema

Here are two good resources on XML Schema: The presentation slides make reference to these example files:

Exercise 1. A Simple Schema

In this first part we just looked at a really simple Schema and a corresponding instance document: xmltech-simple.xsd and xmltech-simple.xml. Download and save these to your local drive. Go ahead and load them into an editor as we'll be looking at them soon. We will now try out the validate program to test if the instance document is compliant with the schema:

validate xmltech-simple.xml
Do you see the following output?
xmltech-simple.xml: 478 ms (4 elems, 1 attrs, 0 spaces, 86 chars)

If so, then the document is compliant! (I know, the output is not very forthcoming.) If it were not compliant, you would see some error messages indicating which parts of the XML document were incorrect.

For the rest of this exercise, edit the xmltech-simple.xml to create both variations on the file that are correct and incorrect. For example, add or remove elements where allowed or disallowed. With each change, run validate to check your results.

Exercise 2. Global Types and Elements

Here is VOResource-v1.0.xsd, the actual IVOA metadata schema used to describe VO resources. Also have a look at xmltech-adil.xml, an example instance document that uses not only this schema but also an extension schema, VODataService-v1.0.xsd.

  1. Notice that the instance document makes use of the xsi:type extension technique.

  2. Find the definition of the DataCollection type (in VODataService-v1.0.xsd).

  3. Try adding additional metadata to xmltech-adil.xml, in particular elements that are not included now.

    Use the validate program to check your results.

    Note: Validating this XML file with the validate program requires access to the network. This is because (as you will see if you look at document's xsi:schemaLocation attribute) it will pull the schema documents directly from the IVOA web site.

Part 2: XPath

Exercise 3. Writing XPaths

Look again at our VOResource instance file, xmltech-adil.xml. Write down the absolute XPath corresponding to the elements or attributes containing the following string values:

  1. 2005-08-01T09:00:00
  2. adil@ncsa.uiuc.edu
  3. stc:AllSky
  4. Millimeter

What would be the relative XPath to the above values if the current context node were the content element?

Part 3: XQuery

Exercise 4. Searching with XQuery

The Carnivore Registry stores its XML resource descriptions in an XML database which supports XQuery. In this exercise, we will try out a few queries.

  1. In another browser window, load the Carnivore XQuery page, http://nvo.caltech.edu:8080/carnivore/advancedquery.

  2. Try a very simple, pre-canned query from Examples pull-down menu. I recommend the last one, in which we search for mention of quasars. Hit the "Submit" button to execute it, and inspect the resuls.

  3. Now let's try our example from the slides:

    declare namespace vr= "http://www.ivoa.net/xml/VOResource/v0.10"; 
    declare namespace vs= "http://www.ivoa.net/xml/VODataService/v0.5"; 
    for $vr in //vr:Resource[@xsi:type="cs:ConeSearch"] 
       where contains($vr//vr:description, "quasar") 
       return 
         <conesearch> 
           <title>{string($vr/vr:title)}</title> 
           <url>{string($vr/vr:interface/vs:accessURL)}</url>
         </conesearch> 
    
    Cut-and-paste this query into the query box and submit it.

  4. Try variations on this query.

Part 4: XSL

Exercise 5: Creating a human-readable view of XML metadata

  1. Download the our sample stylesheet, xmltech-VOResource.xsl, for transforming VOResource metadata description files.
  2. We will use the xalan command to apply our stylesheet:
    xalan -in xmltech-adil.xml -xsl xmltech-VOResource.xsl
    You should now see the following:
    Resource Description Record
    DataCollection
    NCSA Astronomy Digital Image Library (ADIL)
      IVOA Identifier:    ivo://adil.ncsa/adil
    
    Description:
    The ADIL collects published image data in FITS format from a variety of
    telescopes and wavebands and makes them available to the astronomical
    community. Users can search, browse, and download images as well as upload
    their own published images.
    
    Target Communities: University, Research
    Published by:  NCSA Radio Astronomy Imaging
    
  3. Try adding addition information from the input XML document (like the contact information or subject keywords). Use xalan to check the results.

The NVO Summer School is made possible through the support of the National Science Foundation and the National Aeronautics and Space Administration.