Skip to content

Instantly share code, notes, and snippets.

@darelf
Last active August 29, 2015 13:58
Show Gist options
  • Save darelf/9942325 to your computer and use it in GitHub Desktop.
Save darelf/9942325 to your computer and use it in GitHub Desktop.
Access OSTI xml data and parse the results
/*
* 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