All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.examples.server.js Maven / Gradle / Ivy

Go to download

Fast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples.

The newest version!
var http = require('http'),
    XML = require('../lib/xml');

var server = http.createServer(function(req, res) {
    res.writeHead(200, {"Content-Type": "text/xml"});

    var elem = XML.Element({ _attr: { decade: '80s', locale: 'US'} });
    var xml = XML({ toys: elem }, {indent:true, stream:true});

    res.write('\n');

    xml.pipe(res);

    process.nextTick(function () {
        elem.push({ toy: 'Transformers' });
        elem.push({ toy: 'GI Joe' });
        elem.push({ toy: [{name:'He-man'}] });
        elem.close();
    });

});

server.listen(parseInt(process.env.PORT) || 3000);
console.log("server listening on port %d …", server.address().port);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy