@doodad-js/xml
Version:
78 lines (64 loc) • 2.7 kB
Markdown
XML Parser
[![NPM Version][npm-image]][npm-url]
## Installation
```bash
$ npm install -js/xml
```
## Features
- Parses XML from a stream.
- By default, it uses the 'sax' package, but can support any other parser accepting chunks of data.
## Quick Start
```js
"use strict";
require('@doodad-js/core').createRoot()
.then(root => {
return root.Doodad.Modules.load([
{
module: '@doodad-js/xml'
}
]);
})
.then(root => {
const xml = root.Doodad.Tools.Xml;
// NOTE: Random songs
return xml.parse("<songs><song><title>Another Me In Lack'ech</title><artist>Epica</artist></song><song><title>Silent Lucidity</title><artist>Queensryche</artist></song><song><title>One</title><artist>Metallica</artist></song></songs>");
}).then(doc => {
const getItemValue = function(items, name) {
return items.find(name)[0].getChildren().getAt(0).getValue();
};
for (let song of doc.getRoot().getChildren()) {
const items = song.getChildren();
console.log(getItemValue(items, 'title') + " from " + getItemValue(items, 'artist'));
};
}).catch(err => {
console.error(err);
});
```
## Other available packages
- **-js/core**: Object-oriented programming framework (release)
- **-js/cluster**: Cluster manager (alpha)
- **-js/dates**: Dates formatting (beta)
- **-js/http**: Http server (alpha)
- **-js/http_jsonrpc**: JSON-RPC over http server (alpha)
- **-js/io**: I/O module (alpha)
- **-js/ipc**: IPC/RPC server (alpha)
- **-js/json**: JSON parser (alpha)
- **-js/loader**: Scripts loader (beta)
- **-js/locale**: Locales (beta)
- **-js/make**: Make tools for doodad (alpha)
- **-js/mime**: Mime types (beta)
- **-js/minifiers**: Javascript minifier used by doodad (alpha)
- **-js/safeeval**: SafeEval (beta)
- **-js/server**: Servers base module (alpha)
- **-js/templates**: HTML page templates (alpha)
- **-js/terminal**: Terminal (alpha)
- **-js/test**: Test application
- **-js/unicode**: Unicode Tools (beta)
- **-js/widgets**: Widgets base module (alpha)
- **-js/xml**: XML Parser (beta)
## License
[Apache-2.0][license-url]
This package includes a copy and port of the "libxml2" C-library, and also contains copies (raw and minified) of some files of the "sax" package. "libxml2" is licensed under MIT. "sax" is licensed under "The ISC License" and MIT.
[npm-image]: https://img.shields.io/npm/v/@doodad-js/xml.svg
[npm-url]: https://npmjs.org/package/@doodad-js/xml
[license-url]: http://opensource.org/licenses/Apache-2.0