Skip to content

Instantly share code, notes, and snippets.

@MagnusEnger
Created June 10, 2010 11:32
Show Gist options
  • Save MagnusEnger/432855 to your computer and use it in GitHub Desktop.
Save MagnusEnger/432855 to your computer and use it in GitHub Desktop.
Fetch TOCs with the Journal TOCs API and format as HTML
<?php
// Get an ISSN from the querystrin and build a URL for the Journal TOCs API
// http://www.journaltocs.hw.ac.uk/index.php?action=api
$URL = 'http://www.journaltocs.hw.ac.uk/api/journals/' . $_GET['issn'] . '?output=articles';
$xml = simplexml_load_file($URL);
$xml->registerXPathNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
$xml->registerXPathNamespace("prism", "http://prismstandard.org/namespaces/1.2/basic/");
$xml->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
$xml->registerXPathNamespace("mn", "http://usefulinc.com/rss/manifest/");
$xml->registerXPathNamespace("content", "http://purl.org/rss/1.0/modules/content/");
echo('<ul>');
foreach($xml->item as $item) {
$namespaces = $item->getNameSpaces(true);
$dc = $item->children($namespaces['dc']);
// Extract the data
$creator = $dc->creator;
$link = $item->link;
$title = $item->title;
// Build the HTML
echo("<li>$creator: <a href=\"$link\">$title</a></li>");
}
echo('</ul>');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment