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/dev/adqllib ant |
on Windows:
cd %NVOSS_HOME%\java\dev\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: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.xmlDo 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-v0.10.xsd, the actual IVOA metadata schema currently in use 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-v0.5.xsd.-
Notice that the instance document makes use of the
xsi:typeextension technique. -
Find the definition of the
DataCollectiontype.- What type does it extend?
- What metadata does it add beyond its parent's type?
-
Try adding additional metadata to xmltech-adil.xml, in particular elements that are not included now.
- don't worry about making the value sensible
- be sure to use the right namespace prefix
validateprogram to check your results.Note: Validating this XML file with the
validateprogram requires access to the network. This is because (as you will see if you look at document'sxsi:schemaLocationattribute) 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:
- 2005-08-01
- adil@ncsa.uiuc.edu
- vs:AllSky
- Millimeter
What would be the relative XPath 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.
-
In another browser window, load the Carnivore XQuery page, http://nvo.caltech.edu:8080/carnivore/advancedquery.
-
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.
-
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. - Try variations on this query.
Part 4: XSL
Exercise 5: Creating a human-readable view of XML metadata
- Download the our sample stylesheet, xmltech-VOResource.xsl, for transforming VOResource metadata description files.
- We will use the
xalancommand 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
- Try adding addition information from the input XML document
(like the contact information or subject keywords). Use
xalanto check the results.
