Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit end or close event when parsing complete #193

Open
muratgozel opened this issue Sep 11, 2018 · 1 comment
Open

Emit end or close event when parsing complete #193

muratgozel opened this issue Sep 11, 2018 · 1 comment

Comments

@muratgozel
Copy link

How can i know when parsing has done? I've tried to listen "end" and "close" events since they are in the source code but they don't get triggered.

@muratgozel
Copy link
Author

I found that it actually emits close event if it piped to node readable stream. here is the code:

const { Readable } = require('stream')
const expat = require('node-expat')

const data = '<xmldoc>...</xmldoc>'

const xmlParser = new expat.Parser('UTF-8')
xmlParser.on('startElement', function (name, attrs) {})
xmlParser.on('error', function(err) {
  throw err
})
xmlParser.on('close', function() {
  // done!
})

const xmlStrStream = new Readable()
xmlStrStream.push(data)
xmlStrStream.push(null)
xmlStrStream.pipe(xmlParser)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant