xmlbuilder
TypeScript icon, indicating that this package has built-in type declarations

15.1.1 • Public • Published

xmlbuilder-js

An XML builder for node.js similar to java-xmlbuilder.

License NPM Version NPM Downloads

Travis Build Status AppVeyor Build status Dev Dependency Status Code Coverage

Announcing xmlbuilder2:

The new release of xmlbuilder is available at xmlbuilder2! xmlbuilder2 has been redesigned from the ground up to be fully conforming to the modern DOM specification. It supports XML namespaces, provides built-in converters for multiple formats, collection functions, and more. Please see upgrading from xmlbuilder in the wiki.

New development will be focused towards xmlbuilder2; xmlbuilder will only receive critical bug fixes.

Installation:

npm install xmlbuilder

Usage:

var builder = require('xmlbuilder');
 
var xml = builder.create('root')
  .ele('xmlbuilder')
    .ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
  .end({ pretty: true});
 
console.log(xml);

will result in:

<?xml version="1.0"?>
<root>
  <xmlbuilder>
    <repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
  </xmlbuilder>
</root>

It is also possible to convert objects into nodes:

var builder = require('xmlbuilder');
 
var obj = {
  root: {
    xmlbuilder: {
      repo: {
        '@type': 'git', // attributes start with @
        '#text': 'git://github.com/oozcitak/xmlbuilder-js.git' // text node
      }
    }
  }
};
 
var xml = builder.create(obj).end({ pretty: true});
console.log(xml);

If you need to do some processing:

var builder = require('xmlbuilder');
 
var root = builder.create('squares');
root.com('f(x) = x^2');
for(var i = 1; i <= 5; i++)
{
  var item = root.ele('data');
  item.att('x', i);
  item.att('y', i * i);
}
 
var xml = root.end({ pretty: true});
console.log(xml);

This will result in:

<?xml version="1.0"?>
<squares>
  <!-- f(x) = x^2 -->
  <data x="1" y="1"/>
  <data x="2" y="4"/>
  <data x="3" y="9"/>
  <data x="4" y="16"/>
  <data x="5" y="25"/>
</squares>

See the wiki for details and examples for more complex examples.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
15.1.16,748,857latest

Version History

VersionDownloads (Last 7 Days)Published
15.1.16,748,857
15.1.03,573
15.0.0366,699
14.0.01,117,649
13.0.21,998,310
13.0.1380
13.0.081
12.0.121,008
12.0.0467,676
11.0.117,680,856
11.0.01,350
10.1.11,039,043
10.1.0123
10.0.017,461
9.0.72,462,122
9.0.69
9.0.5143
9.0.423,861
9.0.322
9.0.23
9.0.124,656
9.0.0381
8.2.2244,486
8.2.18
8.2.024
8.1.03
8.0.0566
7.0.0946
6.0.03
5.0.128
5.0.02
4.2.1288,004
4.2.074
4.1.02,870
4.0.038,966
3.1.091,451
3.0.00
2.6.542,009
2.6.4121
2.6.33
2.6.227,515
2.6.132
2.6.01
2.5.22,127
2.5.13
2.5.05
2.4.64,198
2.4.5208
2.4.476
2.4.3117
2.4.22
2.4.12
2.4.01
2.3.0227
2.2.16,231
2.1.094
2.0.13
2.0.02
1.1.2219
1.1.12
1.1.02
1.0.27
1.0.18
1.0.06
0.4.337,720
0.4.263,954
0.4.18
0.4.05
0.3.1199
0.3.109
0.3.97
0.3.86
0.3.77
0.3.67
0.3.57
0.3.47
0.3.37
0.3.249
0.3.1115
0.3.07
0.2.25
0.2.15
0.2.07
0.1.87
0.1.75
0.1.67
0.1.57
0.1.47
0.1.37
0.1.2139
0.1.16
0.1.07
0.0.69
0.0.58
0.0.16
0.0.28
0.0.38
0.0.47

Package Sidebar

Install

npm i xmlbuilder

Weekly Downloads

32,827,184

Version

15.1.1

License

MIT

Unpacked Size

321 kB

Total Files

50

Last publish

Collaborators

  • oozcitak