Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add example server

  • Loading branch information...
commit 4bea5970a4504d5e108387cf48b73e4819309fed 1 parent d05d8e2
@dodo dodo authored
Showing with 24 additions and 0 deletions.
  1. +24 −0 examples/server.js
View
24 examples/server.js
@@ -0,0 +1,24 @@
+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('<?xml version="1.0" encoding="utf-8"?>\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);
Please sign in to comment.
Something went wrong with that request. Please try again.