the xml builder that wrap libxmljs
npm install libxmljs-builderthe xml builder that wrap libxmljs
``bash`
$ npm install --save libxmljs-builder
`javascript`
var Builder = require('libxmljs-builder');
var xmlBuilder = new Builder
var doc = xmlBuilder.root('root', {attrA: 'valA', attrB: 'valB'}, function(builder) {
builder.node('nodeA', {attrC: 'valC'}, 'nodeText')
});
console.log(doc.toString());`
that will generate following xml:xml`
`javascript`
var Builder = require('libxmljs-builder');
var xmlBuilder = new Builder
xmlBuilder.defineNS {nsA: 'namespaceA', nsB: 'namespaceB'}
var doc = xmlBuilder.rootNS('nsA', 'root', {attrA: 'valA', attrB: 'valB'}, function(builder) {
builder.nodeNS('nsB', 'nodeA', {attrC: 'valC'}, 'nodeText')
});
console.log(doc.toString());`
that will generate the following xml:xml`
Methods
* defineNS(nsobj, href)
define the namespaces that xml need to use
* nsObj Object|String
if is String, it is the namespace prefix, else it's the prefix-href of namespace
* href String
namespace href, it's valid only if nsObj is String
* return Namespace
* getNS(prefix)
get the namespace object
* prefix String
the namespace's prefix
* return Namespaceroot(name, attrs, content)
*
set the root element
* name String
the element's name
* attrs Object
key-value of attribute list
* content String|Function
if content is String, then it's element's text. if is Function, it can add children node in this function. The function's signature is function(builder), when builder is ChildrenBuilder type.
* return Document
* rootNS(ns, name, attrs, content)
set the root element with namespace
* ns String
the namespace prefix. Other parameters are the same with the root(name, attrs, content) method.
Methods
* node(name, attrs, content)
define the new element. The parameters and return value is the same with root(name, attrs, content).
* nodeNS(ns, name, attrs, content)
define new element with namespace. The parameters and return value is the same with rootNS(ns, name, attrs, content)`.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using gulp.
Copyright (c) 2015 liuxiong. Licensed under the MIT license.
[npm-url]: https://npmjs.org/package/libxmljs-builder
[npm-image]: https://badge.fury.io/js/libxmljs-builder.svg
[travis-url]: https://travis-ci.org/liuxiong332/node-libxmljs-builder
[travis-image]: https://travis-ci.org/liuxiong332/node-libxmljs-builder.svg?branch=master
[daviddm-url]: https://david-dm.org/liuxiong332/node-libxmljs-builder
[daviddm-image]: https://david-dm.org/liuxiong332/node-libxmljs-builder.svg?theme=shields.io
[coveralls-url]: https://coveralls.io/r/liuxiong332/node-libxmljs-builder
[coveralls-image]: https://coveralls.io/repos/liuxiong332/node-libxmljs-builder/badge.png