Created
February 18, 2012 19:41
-
-
Save Zoramite/1860771 to your computer and use it in GitHub Desktop.
Example of using Node.js to parse P2PXML.com file.
This file contains 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
// 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