a gulp plugin to process xml file with xml2js.
The creation of this modules is due to that the module gulp-xml2js is not so powerful as the original xml2js.
check the gulpfile.js
in this module you will see the following:
var gulp = require('gulp'),
rename = require('gulp-rename'),
xml = require('.');
gulp.task('default', function () {
gulp.src('./test/src.xml')
.pipe(xml({
// options to initialize an XML2JS PARSER
parserOpts: {
trim: true
},
// options to initialize an XML2JS BUILDER
buildOpts: {
renderOpts: {
pretty: false
},
allowSurrogateChars: true,
cdata: true
},
// outType: build an xml file or a json string, DEFAULT ture
// callback after building the output contents with the result passed in
// besides, if the return value of callback equals null, undefinded or an empty string and so on,
// it will be igored
callback: function (result) {
return result.replace(/search/g, 'MySearch');
}
}))
// please handle renaming the files by yourself or not
.pipe(rename({
basename: 'dist'
}))
.pipe(gulp.dest('./test'));
});
Yeah, as yo see it's very simple. Just enjoy it!
run the following script:
npm i
npm test
Thanks to the original author @Leonidas-from-XIV and the code pattern of gulp-replace.
MIT License (Expat)