• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

morou/gulp-xml-editor: A gulp plugin to edit XML document based on libxmljs

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

morou/gulp-xml-editor

开源软件地址(OpenSource Url):

https://github.com/morou/gulp-xml-editor

开源编程语言(OpenSource Language):

JavaScript 100.0%

开源软件介绍(OpenSource Introduction):

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
that0n3guy/gulpfile-laravel: Gulpjs file used with laravel发布时间:2022-06-21
下一篇:
tiy-eric/fitness-gulp发布时间:2022-06-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap