In this lab you will use a web service to get new relevant data, transform it via XSLT, and display it in your application. This is similar in structure to the previous lab, but this time you retrieve live data from a different service and not your own database.
Add the "invoke link" described above to your default.htm page AND send an email to the instructor saying that it is there.
See calendar for the deadline on this.
Follow the Plan of Attack below, but here are the specific requirements.
- Copy your Lab06 new Lab07 directory. Your main file should still be called index.html
- Try to keep the functionality from your previous lab (e.g. don't start over and delete things, but you don't have to fix things either. Talk to the instructor if you have a reason to modify this).
- There should be a button(s), link(s), or something to click or interact with such that when you click, one of the following happens:
- You use AJAX to invoke a Perl/PHP proxy
- The proxy invokes a web service (you choose, see below)
- The web service returns XML to the proxy, which returns it to your HTML/JS application
- You transform that XML with XSLT (same general idea as last week, but see details below).
- You display part of the transformed XML in your page.
- All of this should happen within the same HTML page (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. This implies that your web service should accept some argument (talk to the instructor if you find a web service that you really want that doesn't have this).
- It is perfectly fine to insert some new info into your database to make this lab work. For instance, maybe you didn't have zipcodes before, but now you need them for a service - go ahead and add them.
- You may choose any web service (some exceptions below) 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:
- See "Possible Web Services" below.
- 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 (wunderground.com for REST and Flickr for SOAP).
- You probably do NOT want to use a mapping-based web service (we'll add that later).
- You must use XSLT to modify the XML that you get. It should transform the XML so that it fits in with your existing page. Don't just display the XML that you get back! Having some reasonable/nice style and appearance counts here.
- As always, your code must be commented!
- On your default.htm page, provide some good, very specific 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.
- Default.htm must have these additional links:
- The "invoke link": a link that directly invokes your web service, so that clicking on it shows the raw XML returned from your web service. This should not be to a saved XML file - instead, after clicking on this you should be able to modify the argument that is shown in the URL in order to see different XML results.
- Link to test1.xml. In the browser, clicking on this should show the raw XML.
- Link to test2.xml. In the browser, clicking on this should show the result of the transformed XML.
- 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 all requirements.
Suggested plan of attack
Do NOT follow the requirements above in order. Instead...
- First identify a web service and register (if necessary). (www.programmableweb.com)
- Figure out how to access the web service via your browser (or a Perl proxy, if it's SOAP).
- In default.htm, add the "invoke link" to your website directly, to show the API call (if SOAP, then just call your perl script)
- Using the "invoke link", save a sample XML result from the web service - call it test1.xml. You will have to turn this in.
- Copy test1.xml to test2.xml.
- Write a XSLT transformation and test it on test2.xml by adding the XML processing instruction up top. Don't forget to verify your XSLT file alone by loading it in a browser.
- Create a perl script to access your web service and print out the XML.
- Modify your JS to invoke the Perl/PHP proxy to get the dynamic XML data (instead of fetching the static XML), then transform via XSLT and display on your page.
- In default.htm, add instructions AND links to test1.xml and test2.xml (see requirements above).
- Test and make sure everything still works! You'd be surprised how often things get accidentally broken that you were sure worked.
NOTE: all HTML files must validate as XHTML/HTML without errors for full credit. The penalty for a file that does not validate is 10%.
Possible Web Services
- www.programmableweb.com: Huge list, but lots of false positives. Click on "API Directory" - then look for search options. Search for those with protocol of SOAP, REST, or GET. You want the data format to be XML.
- Wikipedia API: Wikipedia API. Use "format=xml". See note below about bad characters in the XML.
- WeatherBug API: Weather page with REST XML. (Note: requires more than one query to get info because of authentication and search. There is a free option, though
that may not be obvious at first).
- Yahoo Finance News: Company lookups. RSS feed is XML and works for this lab.
- GoodReads API: Social media for book readers. Untested API, but looks promising!
- See the plan of attack above!
- Bad Characters in XML: Some web services will return free-form text that was input from a variety of sources and users (wikipedia is one such service). These sometimes contain characters that aren't in the standard ASCII range that your browser expects. The good news is we can strip these characters out very easily in Perl:
$contents =~ s/[^[:ascii:]]+//g;
- XML Contains HTML: Some services return text snippets that contain HTML tags like <span>...</span> and text markup. When you use xsl:value-of to grab these, they will show up on the webpage as <span>, rather than being interpreted as HTML. If you see this, you can turn on a flag to stop it:
<xsl:value-of select="field" disable-output-escaping="yes"/>
- As always, the "Error Console" in Chrome is invaluable.
- For problems with perl, see tips about creating Perl files.
- All of your files for Lab07 should be in a folder called "it452/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 it452/Lab07.
- 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.
- The first page of the output of the 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. Truncated lines are not acceptable.
- Printout of your Perl/PHP file that acts as a proxy.
- Printout of test1.xml returned by the web service you use. Just the first page is okay, if it's long.
- Printout of your XSL file