Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yamadapc/create-xml-ls

Another JS object to XML converter
https://github.com/yamadapc/create-xml-ls

Last synced: about 1 month ago
JSON representation

Another JS object to XML converter

Awesome Lists containing this project

README

        

# create-xml-ls [![Build Status](https://secure.travis-ci.org/yamadapc/create-xml-ls.png?branch=master)](http://travis-ci.org/yamadapc/create-xml-ls)
![](logo.png)

Another JS object to XML converter

*Today, only node 0.10 is supported due to a build fail of libxmljs in node
0.11*

## Instalation

```npm install create-xml-ls```

## Example

### Javascript

#### createXml(obj[, options])

```javascript
var createXml = require('create-xml-ls');

createXml({
something: {
is: 'very',
ugly: {
$attr: {
IMHO: 'it sucks'
}
but: 'sometimes we have to live with it'
}
}
}, { pretty: true });
/* =>

very

sometimes we have to live with it

*/
```
Indentation is off by default, but can be toggled with ```options.pretty``` set
to true.

The default attributes key is ```'$attr'```, but you can also use a custom one
by setting ```options.attributesKey``` to the desired key.
```javascript
createXml({
something:
is: {
attributes: {
'kind': 'of'
},
interesting: 'about this'
}
}, { pretty: true, attributesKey: 'attributes' );
/* =>


about this

*/
```

There's also support for array properties.
```javascript
createXml({
arrayExample: {
sometimes: [
'I',
'had',
'to',
'do',
'this'
]
}
}, { pretty: true });
/* =>

I
had
to
do
this

*/}
```

## License
Copyright (c) 2013 Pedro Yamada. Licensed under the MIT license.

## Donations
Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y