Streaming XML parser and formatter
npm install muxml> Streaming XML parser and formatter
muxml is a Transform stream that accepts XML strings, and emits small chunks containing individual XML elements.
The parser part of this module is built on sax:saxophone:.
On parsing, the stream is broken-up and reassembled so that each opening/closing tag and each text is a chunk. During this process, sax events are re-emitted and are listenable down the pipeline.
Once XML is parsed, this module can optionally format XML in the following fashions:
* XML minification (de-indentation and removal of newlines)
* XML beautification (indentation and usage of newlines)
* striping of comments
* striping of CDATA
* striping of instruction (like ) tags
* striping of declarations
* striping of attributes
* tag filtering based on tag name
muxml is written with ES6/ES2015 syntax, although it is also shipped as an ES5 module with UMD syntax, meaning it can also be used:
* in Node.js >= 4
* in the browser, as global script
* in the browser, with an AMD loader
Also available as a gulp / Grunt plugin, or as a CLI app.
```
$ npm install --save muxml
Suppose a file named example.xml containing the follwing XML
`xml`
then, muxml() returns a transform stream that accepts XML strings and emits XML elements as strings
`js
const muxml = require('muxml');
fs.createReadStream('example.xml')
.pipe(muxml({pretty: false}))
.on('data', function (data) {
console.log(data);
//=> '
});
`
Type: booleantrue
Default:
Set sax parser strict argument
Type: booleantrue
Default:
Prettify the output. If true, output has newlines and indentation.
Type: stringspaces
Default:
When pretty is set to true, indent with either spaces or tabs.
Type: integer2
Default:
When pretty is set to true and indentStyle is set to spaces, then indent with this number of spaces.
Type: integer1
Default:
When pretty is set to true and indentStyle is set to tabs, then indent with this number of tabs.
#### filter
Type: stringnull
Default:
a filter for tag names
Filter XML with tags with name matching the filter.
Type: booleanfalse
Default:
Strip attributes from tags.
Type: booleantrue
Default:
Strip CDATA tags.
Type: booleantrue
Default:
Strip XML comments.
Type: booleantrue
Default:
Strip declarations.
Type: booleantrue
Default:
Strip processing instruction (like ) tags.
Type: object{}
Default:
Set options of sax parser. Note that trim can not be set to false.
#### options
Type: object
as described above
* muxml-cli | CLI for this module
* gulp-muxml | this module as a gulp plugin
* grunt-muxml | this module as a Grunt` plugin
MIT © t1st3