Last active
August 29, 2015 13:58
-
-
Save darelf/9942325 to your computer and use it in GitHub Desktop.
Access OSTI xml data and parse the results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* OSTI is home to lots of scientific, engineering and technical journals and other doucments. | |
* It is part of the US Dept. of Energy. This shows how to retrieve search results from their vast | |
* collection of data as XML and consume it. | |
*/ | |
var xml2js = require('xml2js') | |
var http = require('http') | |
// Get 100 entries from OSTI in the subject area HYDROGEN | |
// See https://www.osti.gov/home/sites/www.osti.gov.home/files/SciTechXMLDataServices1.1.pdf for more info | |
http.get("http://www.osti.gov/scitech/xml.jsp?Subject=HYDROGEN", function(res) { | |
var body = '' | |
res.setEncoding('utf8') | |
res.on('data', function(chunk) { body += chunk }) | |
res.on('end', function() { | |
xml2js.parseString(body, function(err, result) { | |
result['rdf:RDF'].records[0].record.forEach(function(v) { | |
// Log the title to the console .. obviously do something different here with the data | |
console.log(v['dc:title'][0]) | |
}) | |
}) | |
}) | |
}).on('error', function(e) { console.log('ERROR: ' + e.message) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment