node.js - Create a stream of XML document with declaration and doctype tags removed -


heres im trying do
goal: pipe stream of xml document declaration , doctype tag removed.
question
part 1. whats best way go this. should use fs module's createreadstream , createwritestream methods?
part 2. how remove text 1 stream , pipe stream?

you can use fs.createreadstream , fs.createwritestream read , write xml data respectively. remove text need duplex stream both readable , writable. in node 0.10+ can use builtin transform stream. here simple code use transform stream:

var transform = require('stream').transform  var util = require('util'); var fs = require('fs')  util.inherits(mytransform, transform); function mytransform(options) {   if (!(this instanceof mytransform))     return new mytransform(options);    transform.call(this, options);    // init transform   transform.call(this, options); }  mytransform.prototype._transform = function (chunk, encoding, done) {   //do processing chunk   this.push(chunk);   done(); };  rstream = fs.createreadstream('input.xml') wstream = fs.createwritestream('output.xml') tstream = new mytransform()  rstream   .pipe(tstream)   .pipe(wstream) 

Comments