enieber
10/15/2015 - 3:36 AM

xml.md

write-in-xml.js


var readline = require('readline')
var fs = require('fs')
var datas
var versionNew
var file = 'test.xml'


var rl = readline.createInterface({
          input: process.stdin,
          output: process.stdout
        })

fs.readFile(file, function(err, data){
     if(err) throw err

     datas = data+""
       
     var newData = datas.replace('<version>', "")
     var noNewData = newData.replace('</version>', "")

     console.log(" Version now : "+noNewData)
        
    rl.question("What is new version? ", function(answer){
        versionNew = answer.replace(noNewData, answer)
            
        fs.writeFile(file, '<version>'+versionNew+'</version>', function(err){
            if(err) throw err
            console.log("The version "+versionNew+" has been added successfully!")
        })
    
        rl.close()
    })
})

Arquivo.xml


<version>0.0.1</version>