This week we learned how web services can provide useful
data to web applications. In this lab you will use a web service to get new
relevant data, transform it via XSLT, and display it in your application.
- Copy your Lab06 new Lab07 directory. Your main file
should still be called index.html
Here is what you what you want to have when you are
finished. Suggested plan of attach for
getting there is below (read it before
- Everything from previous labs should still work.
- There should be multiple button, links, or
something to click or interact with such that when you click on one the
- You use AJAX
to invoke a Perl/PHP proxy
- The proxy invokes a web service (you choose, see
- The web service returns XML to the proxy, which
returns it to your HTML/JS application
- You transform that XML with XSLT (see details
- You display part of the transformed XML in your
- All of this should happen within your baseline
index.html (e.g. the URL up top should not change)
- The web service must return different results based
on different data in your database.
For instance, if you have people, you might show weather for their
hometown when you click on one. If
you have products, you might show related pictures when you click on it.
Thus, the same web service will be invoked, but different data from you
will yield different results.
- You may choose any web service that returns XML and
that permits you to use it for free non-commercial use (though you will
likely have to register). Start
this early! You may have to wait for a “key”, or it may turn out the
service doesn’t provide what you need. Details:
- Tip: www.programmableweb.com
to find web services. Click on APIs – search for those of type SOAP,
REST, or HTTP (HTTP will behave like REST).
- Try to pick a service that adds real usefulness to
your site. Talk to the instructor
if you need ideas.
- You may not
use the two services used as lecture examples (weather.com for REST
and Flickr for SOAP). However,
Flickr offers other protocols (e.g., REST) which you could use if you
want, but in that case you must make substantive changes to the XSL that
- Your must use a proxy that directly interacts with
the web service (as the two examples in class did). For instance, you may not use one of the Google
interactions behind the scenes.
- You must use XSLT to modify the XML that you get. It should transform the XML so that
it fits in nicely with your existing page. Style and appearance
- As always, your code must be commented!
- On your default.htm page, provide some comments for
a user (e.g. the instructor) on how to use your site. This should be specific to this lab –
e.g. how can I see that your site meets the requirements for this lab?
For instance, what to click, what to enter, etc.
- Suggested plan of attack (see also helpful info at
- Do NOT
follow the requirements above in order. Instead…
- First identify a web service and register (if
- Figure out how to access the web service via your
browser (or a Perl proxy, if it’s SOAP).
- Save a sample XML result from the web service. You will have to turn this in.
- Write a XSLT transformation and test it on the
sample XML file. Don’t forget to verify your XSLT file alone by loading
it in a browser.
- Use JS to invoke the proxy to get the dynamic XML
data, then transform via XSLT and display on your page.
static XML file), apply the XSLT to it, then insert some of the result in
Ensure your page works with Firefox. Having it work on
IE is encouraged but not required.
Ensure all your pages validate and that you have met
NOTE: all HTML files must validate as XHTML without errors
for full credit. The penalty for a file that does not validate is 10%.
- See the plan of attack above!
- General debug strategy:
- First, run Perl from the command line and make sure
it works (see below). Include
actual arguments so you can see it’s really working.
- Second, run Perl via the webserver directly, e.g.
- Finally, try it all from HTML via the browser. If this doesn’t work
- Look first at the Error console!
- Use window.alert() to see what is happening. In particular, check what URL you are
actually using to invoke Perl.
- Did I mention looking at the Error console?
- As always, the “Error Console” in Firefox is
- Perl is easier to debug via the windows command line.
You should first check for syntax errors by just “checking” the file:
perl –c -w myquery.pl
Once that works run it for real:
perl -w myquery.pl
If needed, you can provide CGI arguments like this:
perl –w myquery.pl
- On the command line, database errors will usually
appear automatically. From the
browser, they won’t – instead insert this as a debug:
- CREATE TABLE comments
(USER_NAME VARCHAR(20), TIMESTAMP DATETIME, COMMENT MEDIUMTEXT, PAGE
- INSERT INTO comments
(USER_NAME, TIMESTAMP, COMMENT, PAGE) VALUES ('Jamie', '2006-09-27
11:30:00', 'hi', 2);
- CREATE TABLE topics
(TOPIC VARCHAR(20), OWNER VARCHAR(20));
- INSERT INTO topics
(TOPIC, OWNER) VALUES ('Cars', ‘Jamie’);
- Note: ID is
automatically created with the table, no need to specify it.
- Do not use
the die() function alone – the error it generates can’t be seen from your
All of your files for Lab07 should be in a folder
called "Lab07" (without the quotes) on the Web drive.
Your main page for Lab07 should be called
"index.html" (without the quotes) and placed inside the folder Lab01.
Your instructor will assume that your web pages are
viewable at http://www.mXXXXXX.it452.cs.usna.edu/Lab04/index.html
where XXXXXX is your alpha number. You should check that this URL is viewable
and that everything works correctly from a computer where somebody else is
logged in. If you've goofed and linked to a file on your X drive, this will
help you catch it!
All files must be complete and saved to your Web drive
before you submit the hardcopy of your assignment. Do NOT modify your files
after you have submitted your assignment.
Turn in the following hardcopy on or before the due
date, stapled together in the following order (coversheet on top):
A completed assignment coversheet. Your comments will help us improve the
The first page of the output of the W3C validator, as
run on the final version of your Lab07/index.html. This should show that your document correctly
validated, but turn it in anyway if you can’t get your page to validate.
A printout of the
source to your Lab07/index.html file (not the rendered page that you
normally see with Internet Explorer/Firefox).
Truncated lines are not acceptable – use Crimson Editor vice Notepad if
needed for printing. You could also
paste into Microsoft Word etc. if needed.
does the transformation and insertion is acceptable if you wish.
Printout of your Perl/PHP file that acts as a proxy
Printout of sample
XML returned by the web service you use.
Printout of your XSL file