artdaq_node_server  v1_00_08
 All Classes Namespaces Files Variables Pages
src/node_modules/xml2js/node_modules/xmlbuilder/README.md
1 # xmlbuilder-js
2 
3 An XML builder for [node.js](https://nodejs.org/) similar to
4 [java-xmlbuilder](https://github.com/jmurty/java-xmlbuilder).
5 
6 [![License](http://img.shields.io/npm/l/xmlbuilder.svg?style=flat-square)](http://opensource.org/licenses/MIT)
7 [![NPM Version](http://img.shields.io/npm/v/xmlbuilder.svg?style=flat-square)](https://npmjs.com/package/xmlbuilder)
8 [![NPM Downloads](https://img.shields.io/npm/dm/xmlbuilder.svg?style=flat-square)](https://npmjs.com/package/xmlbuilder)
9 
10 [![Build Status](http://img.shields.io/travis/oozcitak/xmlbuilder-js.svg?style=flat-square)](http://travis-ci.org/oozcitak/xmlbuilder-js)
11 [![Dependency Status](http://img.shields.io/david/oozcitak/xmlbuilder-js.svg?style=flat-square)](https://david-dm.org/oozcitak/xmlbuilder-js)
12 [![Dev Dependency Status](http://img.shields.io/david/dev/oozcitak/xmlbuilder-js.svg?style=flat-square)](https://david-dm.org/oozcitak/xmlbuilder-js)
13 [![Code Coverage](https://img.shields.io/coveralls/oozcitak/xmlbuilder-js.svg?style=flat-square)](https://coveralls.io/github/oozcitak/xmlbuilder-js)
14 
15 ### Installation:
16 
17 ``` sh
18 npm install xmlbuilder
19 ```
20 
21 ### Usage:
22 
23 ``` js
24 var builder = require('xmlbuilder');
25 var xml = builder.create('root')
26  .ele('xmlbuilder')
27  .ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
28  .end({ pretty: true});
29 
30 console.log(xml);
31 ```
32 
33 will result in:
34 
35 ``` xml
36 <?xml version="1.0"?>
37 <root>
38  <xmlbuilder>
39  <repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
40  </xmlbuilder>
41 </root>
42 ```
43 
44 It is also possible to convert objects into nodes:
45 
46 ``` js
47 builder.create({
48  root: {
49  xmlbuilder: {
50  repo: {
51  '@type': 'git', // attributes start with @
52  '#text': 'git://github.com/oozcitak/xmlbuilder-js.git' // text node
53  }
54  }
55  }
56 });
57 ```
58 
59 If you need to do some processing:
60 
61 ``` js
62 var root = builder.create('squares');
63 root.com('f(x) = x^2');
64 for(var i = 1; i <= 5; i++)
65 {
66  var item = root.ele('data');
67  item.att('x', i);
68  item.att('y', i * i);
69 }
70 ```
71 
72 This will result in:
73 
74 ``` xml
75 <?xml version="1.0"?>
76 <squares>
77  <!-- f(x) = x^2 -->
78  <data x="1" y="1"/>
79  <data x="2" y="4"/>
80  <data x="3" y="9"/>
81  <data x="4" y="16"/>
82  <data x="5" y="25"/>
83 </squares>
84 ```
85 
86 See the [wiki](https://github.com/oozcitak/xmlbuilder-js/wiki) for details.