Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

gulp-xml

1.0.5 • Public • Published

gulp-xml

dependencies devDependency Status

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.


Usage

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
            parseOpts: {
                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!

Test

run the following script:

npm i
npm test

Thanks

Thanks to the original author @Leonidas-from-XIV and the code pattern of gulp-replace.

License

MIT License (Expat)

Install

npm i gulp-xml

DownloadsWeekly Downloads

380

Version

1.0.5

License

ISC

Last publish

Collaborators

  • avatar