//======== myStepTool.js let figureName = "Assemble" let xmlFileName ="l-Creo 3D - " +figureName+".pvi" let jsonFileName = figureName+".json" //name is "l-Creo 3D - Assemble.pvi" //================================= var request = require('request'); var fs = require('fs'); let myXmlData=[] let myArr = [] let myJsonArr = [] let TempjsonObj={stepNumber: 0 , step_name_locid: "" , step_name:"",step_acknowledge:false, step_description_locid:"",step_description:""} xml2js = require('xml2js'); var parser = new xml2js.Parser(); fs.readFile(__dirname + '/'+xmlFileName, function(err, data) { parser.parseString(data, function (err, result) { //console.dir(result); let seq_s=result['galaxy_3di:figure']['galaxy_3di:sequence'] //console.log(JSON.stringify(seq_s)) //console.dir( seq_s[0]['galaxy_3di:sequence_step'] ) //console.log( seq_s ) console.log('Done'); let prop_animats=seq_s[0]['galaxy_3di:sequence_step'] prop_animats.forEach(el_function1) }); console.info("jsonArray\n=================\n") console.log(JSON.stringify(myJsonArr)) fs.writeFileSync(__dirname + '/'+jsonFileName, JSON.stringify(myJsonArr, null, 2) , 'utf-8'); }); function el_function1(item, index, arr) { let jsonObj= JSON.parse(JSON.stringify(TempjsonObj)) jsonObj.stepNumber= index; myArr[index] = item['galaxy_3di:property'] //console.log("myArr["+index+"] = "+myArr[index]) //console.dir(myArr[index]) //console.log("myArr["+index+"][1][\'$\'].value = "+myArr[index][1]['$'].value) console.log("myArr["+index+"] ["+ myArr[index][0]['$'].name+ "] = "+myArr[index][0]['$'].value) jsonObj.step_name_locid = myArr[index][0]['$'].value console.log("myArr["+index+"] ["+ myArr[index][1]['$'].name+ "] = "+myArr[index][1]['$'].value) jsonObj.step_name = myArr[index][1]['$'].value console.log("myArr["+index+"] ["+ myArr[index][2]['$'].name+ "] = "+myArr[index][2]['_']) jsonObj.step_acknowledge = myArr[index][2]['_'] console.log("myArr["+index+"] ["+ myArr[index][3]['$'].name+ "] = "+myArr[index][3]['$'].value) jsonObj.step_description_locid = myArr[index][3]['$'].value console.log("myArr["+index+"] ["+ myArr[index][4]['$'].name+ "] = "+myArr[index][4]['$'].value) jsonObj.step_description = myArr[index][4]['$'].value myJsonArr.push(jsonObj) }