https://github.com/pirxpilot/gexode
Primitive XML generator for node.js
https://github.com/pirxpilot/gexode
Last synced: over 1 year ago
JSON representation
Primitive XML generator for node.js
- Host: GitHub
- URL: https://github.com/pirxpilot/gexode
- Owner: pirxpilot
- License: mit
- Created: 2011-02-20T23:21:52.000Z (over 15 years ago)
- Default Branch: main
- Last Pushed: 2023-03-21T11:34:49.000Z (over 3 years ago)
- Last Synced: 2025-03-21T10:01:59.662Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
- License: License
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url]
[![Build Status][build-image]][build-url]
[![Dependency Status][deps-image]][deps-url]
# gexode
Primitive XML generator for node.js
## Example
```js
const { doc, elem } = require(gexode);
const car = doc(elem('car', {wheels: 4}).text('Volvo'));
car.toString();
```
renders as:
```xml
Volvo
```
## Generator mode
`gexode` can also be used as a generator
```js
const { generator } = require('gexode');
const { header, start, el, end } = generator({ pretty: true });
function* cars() {
yield* header();
yield* start('cars');
yield* el('car', { wheels: 4 }, 'Volvo');
yield* end();
}
Array.from(cars()).join('');
```
renders as:
```xml
Volvo
```
### API
`generator(options)`
- `options` - `{ pretty, selfClosing }`
if `pretty` is truthy intendations are generate
if `selfClosing` is truthy empty tags are self closeing ``
- `header` - generate XML header
- `el(name, attribute, text)`- generate a node with attributes (optional) and text (optional), close the node automatically
- `start(name, attribute)`- like `el` but do not close the node
- `end` - close recently opened node
## License
MIT
[npm-image]: https://img.shields.io/npm/v/gexode
[npm-url]: https://npmjs.org/package/gexode
[build-url]: https://github.com/pirxpilot/gexode/actions/workflows/check.yaml
[build-image]: https://img.shields.io/github/actions/workflow/status/pirxpilot/gexode/check.yaml?branch=main
[deps-image]: https://img.shields.io/librariesio/release/npm/gexode
[deps-url]: https://libraries.io/npm/gexode