Learning and Loving JQuery – for the most part
Javascript has always been an area which was lacking for me in terms of skills. Ironically some of the project I’ve been working on of late require Javascript and in a quantity I haven’t written before. So I’ve been digging in and learning more of it. Mostly I’ve been working with JQuery and my love for it has been growing by the moment. Its works terrific with JSON and PHP pages for AJAX actions and has a way of selecting things that reminds me of Xpath.
However, one reason I wanted to use JQuery was its XML support. The problem is that I haven’t had any luck using JQuery with XML. I can’t seem to bring XML back. I don’t know if the problem is a result of either my lack of knowledge or the structure of the XML I’m dealing with. Many web tutorials have been consulted and I’m still stuck.
Rather than continue to bang my head against that wall infinitely, I’ve decided to take a different approach to get the job done. I’ve written PHP that takes my XML and turns it into JSON. JSON + JQuery is truly heaven. Its not what I wanted but it works and sometimes having something done is better than doing it perfectly. When I have a little perspective I’ll return to JQuery and XML and maybe the problem will be clearer.
Using JQuery I’ve been able to build many of the scripts for my 2010 code4lib presentation. This includes a set of crosslist scripts which crosslist print and electronic books and journals. I decided to write these script because its isn’t always clear when a library such as UH has both the print and electronic version of a book or a journal. So I have created a prototype script which adds links for print books to the ebooks in our Serial Solutions list.
I also created a prototype script which adds a Also Available as … link to the full record screen in our library catalog. For e-books it uses the ISBN to search the WorldCat Search API and see if we have that book. If it does it builds a link to the print copy of that book in our catalog.
For print books the script takes the ISBN and sends it to Serial Solutions OpenURL XML API. If it returns a match then it builds a direct link to the ebook.
Also I wrote a script which adds the Peer Reviewed indicator to journals within our library catalog interface.
None of these scripts are in production yet. But I’m hopeful that they will be able to be implemented shortly after my departure. These are just one of a suite of scripts I’ll be showing off at code4lib. All of them use OCLC Web Services. Some have extra special sauce (read other APIs) worked in, some don’t. All of them make library UIs richer and I can’t wait to show them off as a group. I’ll post more details and code on each of them individual a bit later.



Sounds to me like Same origin policy issues rather than anything with XML or jQuery.
You can’t directly call the Serials Solution API from your site using XMLHttpRequest (which jQuery abstracts for you) because it’s not hosted on the same domain. Funnily enough, you CAN ingest JSON from external sites using a technique called jsonp (also abstracted in jQ), which can send GET parameters in the src attribute of a script created in the DOM. All the JSON data is then wrapped in a callback, which jQuery makes for you if so desired.
So, you could ostensibly just mirror the SS API as XML on your server, then work with the XML in jQuery, though I personally prefer JSON.
Hope this helps.
Yes, cross server scripting issues are a horrible pain. IMHO that’s why having a JSON output from an API is so important. What I’m doing is using PHP to parse the Serial Solutions XML and turn it into JSON. Then it doesn’t matter what server I access it from. Works well enough.
I’ve had similar experiences with Jquery. It’s custom made for parsing serialized javascript (JSON), but can’t cut it when it comes to XML, funky namespaces, and tag attributes. I’m not sure you’ll find the tutorial that will show you the way to parse complex XML with Jquery. You might try looking at John Resig’s site (he created Jquery) – http://ejohn.org/. I’ve found some good tips there. In the meantime, washing XML through PHP to create JSON seems like a good solution. I know we’ve talked in passing about the Yahoo Query Language which might also be a way to convert XML into JSON. Check the Open Data tables section at http://developer.yahoo.com/yql/guide/yql-opentables-chapter.html. But that could be a lot of work and you would need the Worldcat data set… In a perfect world, OCLC web services would start serving JSON as one of their output formats. I’m sure they are already thinking about it.
Cool project Karen. It sounds like you wrote your own wrapper around the Serial Solutions API that outputs JSON. I’ve used this link360 project out of Virginia Tech. It’s a Python web service that transforms SerSol XML into JSON.
I wonder if Serial Solutions would add JSON support. It could make the API more useful.
Yes, I wrote a PHP wrapper because of the cross server scripting issue. If I wanted to do it natively in XML I would try JQuery plus a Apache_Proxy to solve the cross server scripting issue.
Jason,
I think the cross server scripting issues can be got around via Apache and mod_proxy to make the script look like its on the same server. That being said one would still have to figure out how to manipulate the XML in Jquery. It doesn’t look that bad but I personally need to do some testing by putting an example of static WorldCat Search API XML on my server and writing JQuery to parse that.