Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/izatop/o2xml
Convert JavaScript objects to XML
https://github.com/izatop/o2xml
Last synced: 7 days ago
JSON representation
Convert JavaScript objects to XML
- Host: GitHub
- URL: https://github.com/izatop/o2xml
- Owner: izatop
- License: mit
- Created: 2016-03-18T07:27:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T19:52:11.000Z (over 1 year ago)
- Last Synced: 2024-09-18T12:14:20.771Z (2 months ago)
- Language: TypeScript
- Size: 28.1 MB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# o2xml
Simple object to XML converter.## Install
`npm install o2xml`
## Simple example
```js
var o2xml = require('o2xml');
var object = {
thing: {
'@flag': true,
'@number': 123,
'@date': new Date(),
items: {
'@length': 2,
item: [
{name: 'Alexander', birth: new Date('2002-12-09')},
{name: 'Daniel', birth: new Date('1991-03-22')}
]
}
}
}console.log(o2xml.transform(object, {pretty: true}));
```converts to:
```xml
Alexander
2002-12-09T00:00:00.000Z
Daniel
1991-03-22T00:00:00.000Z
```
## Options
- pretty: `true|false` make pretty XML (default: `false`).
- indent: `\t` spacing (default: two spaces).
- declaration: `true` write the XML declaration (default: `false`).
- formatters: `{string:fn, boolean:fn, number:fn, date:fn}` format and escape functions.## Mix strings, nodes and attributes
```js
var o2xml = require('o2xml');
var object = {
div: {
'@id': 'id',
'#text': 'Hello, ',
span: {
'@style': 'font-weight: bold',
'#text': 'World'
},
'#text2': '!'
}
}console.log(o2xml.transform(object));
```converts to:
```xml
Hello, World!
```## Note
- Text escape by default (amp, quote, single quote, left/right angle brackets).
- Node.js Buffer will be converted to base64 encoded string.
- String nodes must start with `#` and key must be unique in space.