Wednesday, 21 March 2007

Week 21 - Revision

There will be a lecture this Friday to help you prepare your revision over Easter. We will look at the exam structure and last year's paper. I also want to gather your thoughts on topics which would benefit from additional revision material to present after Easter, although we still have material to cover after Easter.

The workshop will be on the representation of time using the tutorial on the SIMILE timeline project. Think of this as a GoogleEarth of time.

Tuesday, 20 March 2007

Multiple nodes in PHP

Several of you have asked about looping round elements in XML. This is obviously desirable because, although only six places are asked for in the data, the code should not have to change when a new place is added.

Heres how to do it - [Caution - this code is unchecked]



//assume places.xml contains multiple places, each with a name and description

$placesxml = simplexml_load_file("places.xml");

$places = $placesxml->xpath("//Place");

// $places is now an array of XML elements, each a Place element

foreach ($places as $place) {

//$place now points to each Place in the XML document in turn
// so we can use object references to access the elements within a Place

print $place->name, $place->description;

// or even XPath expression as well

// and of course, if the are repeated elements in Place, such Link, with elements
//url and text, we can use a inner loop to work with these

foreach( $place->Link as $link) {
print "<a href='$link->url'/>$link->text</a>"
}
}

Wednesday, 14 March 2007

Week 20 - Sematic Web -16th of March

We are going to continue to look at the Semantic Web. This week we are going to look at this excellent introduction to the Semantic Web, Schema Languages and Ontology Languages. Then, for self-study, read the section on RDF Schema in the RDF primer that I gave out last week.

Further reading - see the links for last week.

Sunday, 4 March 2007

Week 19 - RDF - 9th of March

In the next two weeks we are going to looking at RDF and RDF Schema languages. We will be reading the RDF primer so please take a look at this document.

See also a short set of slides and the handout for the session.

Further reading:

Wednesday, 28 February 2007

Week 18 - XSLT

XSLT is a rather different language for transforming XML documents than XQuery, but it shares much of the same functionaility. It is more widely used than XQuery partly because there are a number of XSLT processors readily available to use server-side and browsers now include an XSLT processor so that the transformation can be made in the client.

I also want show how XML schemas can be used - for validation of an XML document, and in InfoPath to create a data entry form.


Workshop


Based on the sample data, stylesheet and CSS in this directory

http://www.cems.uwe.ac.uk/~cjwallac/apps/scotch/


1. Copy these files to a directory of your own. There is a zip of the files you need.

2. Test distillery-2.xml to make sure it is working as it does in my directory

3. Make a simple modifucation to the CSS to change the output

4. Add another simple template to the XSLT to display another item of information in the file.

5. Modify the stylesheet for distilleries to display

6. Use InfoPath to create a simple form for either the whisky data or for your own data.

Thursday, 22 February 2007

Week 17 - Xquery and XML database

This week we look at an alternative technology for working with XML. This uses a language called XQuery which is an extension of XPath. There are many XQuery implementations and we will be using one which is part of an open-source project providing a native XML databas.

Monday, 19 February 2007

Periodic table of Visualization Methods

Visual-Literacy.org has published this great Periodic Table of methods of visualisation. This displays around 100 diagram types, with examples and a multi-faceted classification by:
  • simple to complex
  • data/information/concept/strategy/metaphor/compound
  • process/structure
  • detail/overview
  • divergence/convergence
The web page uses a Javascript library to display an example of a diagram type when you mouse-over its box. A neat trick but perhaps not very accessible, so I took the liberty of massaging this table to create a full listing of all the diagram types in alphabetical order. This format is more convenient for my purpose when teaching, and is a nice example of XML-scraping using XQuery.

These listings are made by:
  1. taking the HTML source of the Periodic table
  2. loading it into the eXist database. The source is accepted by eXist even though it is not well formed XML - missing quotes, bare <>
  3. writing a query on XQuery to generate the page.
    1. Find the html document with 'Periodic' in the title
    2. Find all the A tags,
    3. Get the onmouseover attribute
    4. use some string functions to get the name and the source of the image from this string
    5. sort by name
    6. generate a div per tag
Here is the basic XQuery script for the plain listing:

List of methods

for $item in data(/HTML[contains(.//TITLE,'Periodic')]//A/@onmouseover)
let $name := lower-case(substring-before(substring-after($item,"window.status='"),"';"))
let $pix := substring-before(substring-after($item,'src="'),'">')
where string-length($pix) >0
order by $name
return
<div><a href="'http://www.visual-literacy.org/periodic_table/{$pix}'">{$name}</a>
</div>

In fact, instead of running a query against the raw HTML, I wrote a slightly different query to generate a simple XML file in which the basic data was stored in alphabetical order. Using an intermediate file also allow me to correct a couple of typos in the method names, and of course it is faster to generate the page. In addition, I've added the facility for a user to group methods and tag the group. Some links to Google images and Wikipedia have been added too. There's a lot more could be done with this.


Now what would be nice would be to get the raw data including the class names as XML so it could be re-organised and extended, without having to descend to scraping.