Giter VIP home page Giter VIP logo

gulp-xml-editor-re's Introduction

gulp-xml-editor-re

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


This is a forked package from gulp-xml-editor with libxmljs upgraded to the latest version, since that package seems like deprecated.


Usage

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

/*
  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

gulp-xml-editor-re's People

Contributors

morou avatar bigmurry avatar jonmikelm avatar juriejan avatar michaeltaylor3d avatar diaomouren avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.