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: , , , , , , , , , , , ,




2 Responses to “Extending Blyberg’s XMLOPAC Class”