gxe

gulp-xml-editor

A gulp plugin to edit XML document based on libxmljs

Showing:

Popularity

Downloads/wk

0

GitHub Stars

6

Maintenance

Last Commit

7yrs ago

Contributors

6

Package

Dependencies

3

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

gulp-xml-editor

gulp-xml-editor is a gulp plugin to edit XML document based on libxmljs.

Usage

var xeditor = require("gulp-xml-editor");

/*
  edit XML document by using user specific object
*/
gulp.src("./manifest.xml")
  .pipe(xeditor([
    {path: '//name', text: 'new names'},
    {path: '//version', attr: {'major': '2'}}
  ]))
  .pipe(gulp.dest("./dest"));

/*
  edit XML document by using user specific object using a namespace
*/
gulp.src("./manifest.xml")
  .pipe(xeditor([
    {path: '//xmlns:name', text: 'new names'},
    {path: '//xmlns:version', attr: {'major': '2'}}
  ], 'http://www.w3.org/ns/widgets'))
  .pipe(gulp.dest("./dest"));


/*
  edit XML document by using user specific function
*/
gulp.src("./manifest.xml")
  .pipe(xeditor(function(xml, xmljs) {

    // 'xml' is libxmljs Document object.
    xml.get('//key[./text()="Version"]').nextElement().text('2.0.0');

    // 'xmljs' is libxmljs object. you can call any libxmljs function.
    var child = new xmljs.Element(xml, 'note');
    child.text('some text');
    xml.get('//description').addChild(child);

    // must return libxmljs Document object.
    return xml;
  }))
  .pipe(gulp.dest("./dest"));

Note

Please see libxmljs wiki page to get more information about libxmljs API.

API

xeditor(editorObjects)

editorObjects

Type: Array of object

The object must be one of following.

// to modify(or add) the text of the element
{path: 'xpath to the element', text: 'new text value'}

// to modify(or add) a attribute of the element
{path: 'xpath to the element', attr: {'attrName': 'attrValue'}}

// to modify(or add) some attributes of the element
{path: 'xpath to the element', attrs: [
  {'attrName1': 'attrValue1'},
  {'attrName2': 'attrValue2'}
]}

You can't specify xpath to attribute nor text node.

xeditor(editorFunction)

editorFunction

Type: function

The editorFunction must have the following signature: function (xml, [xmljs]) {}, and must return libxmljs Document object. The xml argument is libxmljs Document object, and the xmljs argument is libxmljs object.

License

MIT License

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial