Socket
Book a DemoInstallSign in
Socket

gulp-xml-editor

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-xml-editor

A gulp plugin to edit XML document (libxmljs wrapper)

2.2.1
latest
Source
npmnpm
Version published
Weekly downloads
6
-45.45%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

gulpplugin

FAQs

Package last updated on 01 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.