-
-
Save jkantr/e2eaa50ee8a17a3fe45e8f70eaa7bc55 to your computer and use it in GitHub Desktop.
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
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