Skip to content

Instantly share code, notes, and snippets.

@Zoramite
Created February 18, 2012 19:41
Show Gist options
  • Save Zoramite/1860771 to your computer and use it in GitHub Desktop.
Save Zoramite/1860771 to your computer and use it in GitHub Desktop.
Example of using Node.js to parse P2PXML.com file.
// Usage: node p2p.js
var xml2object = require('xml2object'); // npm install xml2object
var filename = 'prosper.xml';
// Create a parser to look for Loan objects in the xml file
var parser = new xml2object(filename, ['Loan']);
// Handle any errors
parser.on('error', function (error) {
console.error(error);
throw error;
});
// Use any loans found in the XML file
parser.on('object', function(name, obj) {
// TODO Do something with the Loan...
});
// Log when the file is done being parsed
parser.on('end', function() {
console.log('Finished reading file');
});
// Start parsing the XML file
parser.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment