00001 # xmlbuilder-js
00002
00003 An XML builder for [node.js](https:
00004 [java-xmlbuilder](https:
00005
00006 [;
00024 var xml = builder.create('root')
00025 .ele('xmlbuilder')
00026 .ele('repo', {'type': 'git'}, 'git://github.com/oozcitak/xmlbuilder-js.git')
00027 .end({ pretty: true});
00028
00029 console.log(xml);
00030 ```
00031
00032 will result in:
00033
00034 ``` xml
00035 <?xml version="1.0"?>
00036 <root>
00037 <xmlbuilder>
00038 <repo type="git">git:
00039 </xmlbuilder>
00040 </root>
00041 ```
00042
00043 It is also possible to convert objects into nodes:
00044
00045 ``` js
00046 builder.create({
00047 root: {
00048 xmlbuilder: {
00049 repo: {
00050 '@type': 'git',
00051 '#text': 'git://github.com/oozcitak/xmlbuilder-js.git'
00052 }
00053 }
00054 }
00055 });
00056 ```
00057
00058 If you need to do some processing:
00059
00060 ``` js
00061 var root = builder.create('squares');
00062 root.com('f(x) = x^2');
00063 for(var i = 1; i <= 5; i++)
00064 {
00065 var item = root.ele('data');
00066 item.att('x', i);
00067 item.att('y', i * i);
00068 }
00069 ```
00070
00071 This will result in:
00072
00073 ``` xml
00074 <?xml version="1.0"?>
00075 <squares>
00076 <!-- f(x) = x^2 -->
00077 <data x="1" y="1"/>
00078 <data x="2" y="4"/>
00079 <data x="3" y="9"/>
00080 <data x="4" y="16"/>
00081 <data x="5" y="25"/>
00082 </squares>
00083 ```
00084
00085 See the [wiki](https: