Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
libxmljs-builder
Advanced tools
the xml builder that wrap libxmljs
Weekly downloads
Readme
the xml builder that wrap libxmljs
$ npm install --save libxmljs-builder
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:
<root attrA="valA" attrB="valB">
<nodeA attrC="valC">nodeText<nodeA>
</root>
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:
<nsA:root xmlns:nsA="namespaceA" xmlns:nsB="namespaceB" xmlns:nsC="namespaceC" attrA="valA" attrB="valB">
<nsB:nodeA attrC="valC">nodeText</nsB:nodeA>
</nsA:root>
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
Namespace
root(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.
FAQs
the xml builder that wrap libxmljs
The npm package libxmljs-builder receives a total of 4 weekly downloads. As such, libxmljs-builder popularity was classified as not popular.
We found that libxmljs-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.