OAI, YQL and JSON

Now that Nature has an OAI-PMH interface, I thought I'd make a YQL Open Data Table to sit in front of it, returning the results as JSON.

The Data Table is a simple XML file (simpler in this case because it's only returning a single item in the results, so there's no need for pagination):

<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
  <meta>
    <author>Alf Eaton</author>
    <documentationURL>http://www.nature.com/oai</documentationURL>
  </meta>
  <bindings>
    <select itemPath="OAI-PMH.GetRecord.record.metadata.pam:message.pam:article.head" produces="XML">
      <urls>
        <url>http://www.nature.com/oai/request?verb=GetRecord&metadataPrefix=pam&identifier=oai:nature.com:{doi}</url>
      </urls>
      <inputs>
        <key id="doi" type="xs:string" paramType="path" required="true"/>
      </inputs>
    </select>
  </bindings>
</table>

Note that the namespaced items are parsed using just their literal prefixes, rather than the full URI, the same as in Yahoo Pipes.

Once that file is online, we can use it in a YQL query:

USE "http://alf.hubmed.org/datatables/nature-oai-doi-pam.xml" as natureoai;
SELECT * FROM natureoai WHERE doi = "10.1038/nature07935";

YQL queries can also be run outside of the console, returning the results as JSON or XML. Here's the result of the query above, as JSON or XML.

Finally, here's some PHP code to construct a query, submit the request and parse the JSON response:

<?php
    
$query = 'USE "http://alf.hubmed.org/datatables/nature-oai-doi-pam.xml" as natureoai; 
SELECT * FROM natureoai WHERE doi = "10.1038/nature07935";';
$params = array('q' => $query, 'format' => 'json');
$data = json_decode(file_get_contents('http://query.yahooapis.com/v1/public/yql?' . http_build_query($params)));
$meta = $data->query->results->head;
print_r($meta);
and the data itself:
(
    [identifier] => doi:10.1038/nature07935
    [title] => Single Lgr5 stem cells build cryptvillus structures in vitro without a mesenchymal niche
    [creator] => Array
        (
            [0] => Toshiro Sato
            [1] => Robert G. Vries
            [2] => Hugo J. Snippert
            [3] => Marc van de Wetering
            [4] => Nick Barker
            [5] => Daniel E. Stange
            [6] => Johan H. van Es
            [7] => Arie Abo
            [8] => Pekka Kujala
            [9] => Peter J. Peters
            [10] => Hans Clevers
        )
    [publicationName] => Nature
    [issn] => 0028-0836
    [eIssn] => 1476-4687
    [doi] => 10.1038/nature07935
    [publisher] => Nature Publishing Group
    [publicationDate] => 2009-03-29
    [volume] => 459
    [number] => 7244
    [startingPage] => 262
    [url] => http://dx.doi.org/10.1038/nature07935
    [copyright] => © 2009 Macmillan Publishers Limited. All rights reserved
)