npm install xml-lexer

Simple JavaScript Lexer for XML documents
If you are looking for a XML Reader/Parser to convert XML documents into Javascript objects, check my other projects:
- xml-reader
- xml-query
``bash`
npm install --save xml-lexer
`javascript
const lexer = require('xml-lexer').create();
const xml =
;
lexer.on('data', (data) => console.log(data));
lexer.write(xml);
/*
Console output:
{ type: 'open-tag', value: 'hello' }
{ type: 'attribute-name', value: 'color' }
{ type: 'attribute-value', value: 'blue' }
{ type: 'open-tag', value: 'greeting' }
{ type: 'data', value: 'Hello, world!' }
{ type: 'close-tag', value: 'greeting' }
{ type: 'close-tag', value: 'hello' }
*/
`$3
`javascript
const lexer = require('xml-lexer').create();
const chunk1 =
const chunk2 = ing>Hello, world!;
lexer.on('data', (data) => console.log(data));
lexer.write(chunk1);
lexer.write(chunk2);
/*
Console output:
{ type: 'open-tag', value: 'hello' }
{ type: 'open-tag', value: 'greeting' }
{ type: 'data', value: 'Hello, world!' }
{ type: 'close-tag', value: 'greeting' }
{ type: 'close-tag', value: 'hello' }
*/
`
`javascript
const lexer = require('xml-lexer').create();
lexer.on('data', (data) => console.log(data));
lexer.write(<);
/*
Console output (note the open-tag value):
{ type: 'open-tag', value: '
{ type: 'close-tag', value: 'hello' }
*/
`
`javascript
const Lexer = require('xml-lexer');
const lexer = Lexer.create();
lexer.stateMachine[Lexer.State.tagBegin][Lexer.Action.lt] = () => {};
lexer.stateMachine[Lexer.State.tagName][Lexer.Action.error] = () => {};
lexer.on('data', (data) => console.log(data));
lexer.write(<);
/*
Console output (note the fixed open-tag value):
{ type: 'open-tag', value: 'hello' }
{ type: 'data', value: 'hi' }
{ type: 'close-tag', value: 'hello' }
*/
``
MIT