Extending Blyberg’s XMLOPAC Class
Update: John updated the class to 1.5 and included this function.
AADL‘s John Blyberg is doing some great stuff with III’s XML Server, and his XMLOPAC PHP class is just what we need to start making use of the product (and cut through the bad XML it outputs). I’ve started re-writing the work I did previously, and I’m taking good advantage of the get_opac_data()
function in that class.
But, I also needed a way to execute a search against the OPAC and get only the matching bib numbers back, so I extended the class with a get_opac_bibns()
function to do just that.
Here it is:
public function get_opac_bibns($searchterms) { $xmlopacurl = 'http://' . $this->opacserver . '/xmlopac/' . $searchterms; $result[xmlurl] = $xmlopacurl; $xmlraw = utf8_encode(file_get_contents($xmlopacurl)); $xmlraw = preg_replace('%>[&\x80-\xFF](.*?)<\/%s', '>GarbageData</', $xmlraw); $xml = simplexml_load_string($xmlraw); foreach ($xml->xpath('//RecordId') as $bib) { $result[bibns][] = substr(((string) $bib->RecordKey), 1); } return($result); }
How to use it? Add this function to the current version of the XMLOPAC class and call it like this:
<?php require_once('xmlopac.php'); $opac_server = 'opac.site.edu'; $xmlopac = new xmlopac; $xmlopac->opacserver = $opac_server; $searchterms = 'Xthomas+jefferson/0/0/1/150?avsrank=D'; $result = $xmlopac->get_opac_bibns($searchterms); print_r($result); ?>
Why only the bib numbers? Because I’m using those bib numbers against a cache of catalog data I’ve built in MySQL. Why go through all that? Because problems are meant to be overcome. I’m using this in my prototype catalog search that clusters search results based on catalog metadata (demoed in my NEASIS&T presentation on OPAC hacks recently).
Technorati Tags: bib numbers, bibnumbers, extension, libraries, library, library catalog, opac data, php, php class, query, web service, web services, xml server
November 30th, 2005 at 3:47 pm
[…] I had a pleasant surprise this morning when I read that Casey had extended my XMLOPAC class. He’s written a function that takes a search term, then returns an array of bib-nums for that search. He’s hoping to create clustered search results, and his function may be a component of that. Yes, necessity is the mother of all invention. […]
December 20th, 2005 at 1:12 pm
[…] I released my php xmlopac class for III, and Casey Bisson contributed two very useful functions. Casey’s contribution inspired me to make public a bit of code to access and cache amazon images. This, in turn, caught Chris Deweese’s attention who is now working on an ASP derivative. […]