Skip to content

Instantly share code, notes, and snippets.

@jkantr
Forked from enricopolanski/node
Last active November 30, 2017 22:13
Show Gist options
  • Save jkantr/e2eaa50ee8a17a3fe45e8f70eaa7bc55 to your computer and use it in GitHub Desktop.
Save jkantr/e2eaa50ee8a17a3fe45e8f70eaa7bc55 to your computer and use it in GitHub Desktop.
var fs = require("fs");
var path = require("path");
var cheerio = require("cheerio");
module.exports = (mypath) => {
var inputFile = fs.readFileSync(mypath, "utf8");
var $ = cheerio.load(inputFile, {xmlMode:true});
// defines the selector
var relationship_number = $("Relationship").filter("[Id]").length;
// Initialize an empty object
var relationship_object = {};
// loops over the relationship xml in order to find the relationship Id and the target
// and adds the value to the relationship_object
for (i=0; i < relationship_number; i++){
relationship_object[$("Relationship").filter("[Id]")[i].attribs.Id] = $("Relationship").filter("[Id]")[i].attribs.Target;
}
// gets a confirmation in console of correct parsing
if(Object.keys(relationship_object).length===relationship_number){
console.log("Relationships parsed successfully")
}
return relationship_object;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment