Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/titarenko/opixml
Opinionated XML generator and parser
https://github.com/titarenko/opixml
Last synced: about 1 month ago
JSON representation
Opinionated XML generator and parser
- Host: GitHub
- URL: https://github.com/titarenko/opixml
- Owner: titarenko
- Created: 2015-10-05T08:44:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-23T06:37:53.000Z (over 8 years ago)
- Last Synced: 2024-11-12T21:07:02.764Z (about 2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpiXML
Opinionated XML generator and parser.
[![Build Status](https://travis-ci.org/titarenko/opixml.svg?branch=master)](https://travis-ci.org/titarenko/opixml)
[![Coverage Status](https://coveralls.io/repos/github/titarenko/opixml/badge.svg?branch=master)](https://coveralls.io/github/titarenko/opixml?branch=master)## Installation
```sh
npm i opixml --save
```## Description
Under the hood it's built on top of `xml2js` and `js2xmlparser`, but has unified interface and certain rules of mapping JS to XML and vice versa. You can pass options object for each library in appropriate method as second argument.
Mapping rules:
- everything that is scalar is interperted as attribute
- everything that is non-scalar is interpreted as node
- with only one exception: if something is an object with one and only one scalar property `_`, then it will be treated as a value-node (see example)## Example
```js
var obj = {
root: {
attr: '10',
subnode: { attr: 'foo' },
othernode: { _: 'value' },
container: {
item: [
{ one: { _: '1' } },
{ two: { value: '2' } }
]
},
container2: {
item: [
{ _: 1 },
{ _: 2 }
]
}
}
};
opixml.toXml(obj).then(console.log);
``````xml
value
1
1
2
```
```js
opixml.fromXml(xml).then(console.log); // you'd see obj deserialized from XML
```## License
MIT