在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):morou/gulp-xml-editor开源软件地址(OpenSource Url):https://github.com/morou/gulp-xml-editor开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):gulp-xml-editorgulp-xml-editor is a gulp plugin to edit XML document based on libxmljs. Usagevar 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")); NotePlease see libxmljs wiki page to get more information about libxmljs API. APIxeditor(editorObjects)editorObjectsType: 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)editorFunctionType: The License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论