-1

Just tried xmlbuilder for node.js; Got into the trouble: cannot display variables inside XML structure:

var http = require('http'), os = require('os'), builder = require('xmlbuilder');
var totalmem = os.totalmem();
var totalmem = os.totalmem();
var xml = builder.create('OS')
  .ele('Env')
    .ele('OS_RAM_TOTAL', totalmem)
  .end({ pretty: true});
  console.log(xml);

And this gives the structured XML:

<OS>
 <Env>
   </OS_RAM_TOTAL>
 </Env>
</OS>

As you see variable totalmem is missing..

Any ideas?

Tadas Davidsonas
  • 1,859
  • 4
  • 16
  • 19

1 Answers1

0

Already found the solution:

var xml = builder.create('OS')
  .ele('Env')
    .ele('OS_RAM_TOTAL', {}, totalmem)
  .end({ pretty: true});
  console.log(xml);
Tadas Davidsonas
  • 1,859
  • 4
  • 16
  • 19