node-libxmljs-builder
the xml builder that wrap libxmljs
Install
$ npm install --save libxmljs-builder
Usage
Create document and child nodes
var Builder = ;var xmlBuilder = var doc = xmlBuilder;console;
that will generate following xml:
nodeText
create document with nameapce
var Builder = ;var xmlBuilder = xmlBuilderdefineNS nsA: 'namespaceA' nsB: 'namespaceB'var doc = xmlBuilder;console;
that will generate the following xml:
nodeText
API
class XmlBuilder
Methods
-
defineNS(nsobj, href)
define the namespaces that xml need to use
-
nsObj
Object|Stringif is String, it is the namespace prefix, else it's the prefix-href of namespace
-
href
Stringnamespace href, it's valid only if nsObj is String
-
return
Namespace
-
-
getNS(prefix)
get the namespace object
-
prefix
Stringthe namespace's prefix
-
return
Namespace
-
-
root(name, attrs, content)
set the root element
-
name
Stringthe element's name
-
attrs
Objectkey-value of attribute list
-
content
String|Functionif 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)
, whenbuilder
isChildrenBuilder
type. -
return
Document
-
-
rootNS(ns, name, attrs, content)
set the root element with namespace
-
ns
Stringthe namespace prefix. Other parameters are the same with the
root(name, attrs, content)
method.
-
class ChildrenBuilder
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)
.
Contributing
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.
License
Copyright (c) 2015 liuxiong. Licensed under the MIT license.