Using an XML Web Service

Assignment 4 — Web-Based Services (INFOSYS 290-3; Fall 2006)

Assigned: 2006-10-09 / Due: 2006-10-16

Author: Erik Wilde

Introduction: The bibliography service has now been extended to provide the information in XML. In this assignment, PHP5's SimpleXML implementation is used to extract information from the XML. Now it becomes possible to build a service which not only is build around the data provided by the query service, but selectively reuses parts of it to provide links to related information provided by 3rd party services.
Resources: Simple Bibliography Search Service (delivering HTML or XML)
PHP SimpleXML
Web and XML Glossary (example entry)
Google Scholar (example entry)
Instructions:

Using the updated Simple Bibliography Search Service (delivering HTML or XML), it is now possible to request XML instead of HTML. Using the SimpleXML extension of PHP5 (remember that you must go through http://people.ischool.berkeley.edu/~yourname/ to make this work, otherwise PHP4 will be used to process your PHP page!), you should now extract some of the data being returned, and use it to create custom links. For example, for each reference being returned you might want to output the title. The following PHP code (only supporting author queries, add the other query terms to make it more flexible) shows how to generate a list of titles from the returned XML:

<ul>
<?php

include "Snoopy.class.php";
$snoopy = new Snoopy;

import_request_variables("g", "formval_") ;

$snoopy->fetch("http://dret.net/lectures/services-fall06/a/4/query.php?format=xml&author=" . urlencode($formval_author));

$xml = new SimpleXMLElement($snoopy->results);

foreach ($xml->xpath('//title[@type = "sharef:primaryTitle"]') as $title) {
   echo '<li>' , $title , '</li>'; }

?>
</ul>

You are not required to add anything else but the title in the output of the service, because some of the XML would have to be processed in a non-trivial way to produce nicely looking output (but some information is easily accessible, such as the date information or links to resources, simply look at the XML if you would like to find out more).

The above code retrieves XML and produces an HTML list of the titles. In this assignment, you now have to use some information from the XML to add useful links to other services. You may choose any service that you think would be useful, but the following examples could be interesting:

  1. The Online Bibliography contains formatted version of all bibliography entries, for each entry you get from the bibliography query service, there is a complete entry at http://dret.net/biblio/reference/id, with the id being the @name in the reference you get from the bibliography query service.
  2. The Web and XML Glossary provides information about Web and XML technologies. Each topic which is found within the XML provided by the bibliography service can be assumed to have a corresponding entry in the glossary (this is not entirely true, but close enough for our purposes).
  3. Google Scholar is service for searching for scholarly articles, and one of the most useful query types there is the query for person names. Since the names are available as individual elements in the XML provided by the bibliography service, it is easy to use these names to compose search string for Google Scholar.

For this assignment, you are not supposed to actually contact the services you link to (we will do this is the next assignment), so all you need to do is figure out how to assemble the HTML code which is required to generate such a link. For example, for the three examples above, in the HTML that you generate, there should be something similar to the following markup for one example entry:

  1. <li>A Compact Syntax for XML Schema <a href="http://dret.net/biblio/reference/wil03k">Bibliography</a></li>
  2. <li>A Compact Syntax for XML Schema <a href="http://dret.net/glossary/xscs">Topic "xscs"</a></li>
  3. <li>A Compact Syntax for XML Schema <a href="http://scholar.google.com/scholar?q=A+Compact+Syntax+for+XML+Schema">Google Scholar</a></li>

You can use your HTML form from the last assignment to build an HTML interface to your new PHP. Your old interface will now produce an output which not only shows information from the bibliography search service, but also provides convenient shortcuts to get more information from other services.


please send comments to dret@sims.berkeley.edu
last modification on Friday, 02-Mar-2007 19:39:32 MET
valid CSS! valid XHTML 1.0!