Skip to content

Raiyee/gulp-xml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
            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!

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)

About

a gulp plugin to process xml file with xml2js(node-xml2js)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published