-
Notifications
You must be signed in to change notification settings - Fork 4
XMLIterator
do- edited this page Oct 16, 2022
·
17 revisions
XMLIterator is a low level synchronous XML parser implemented as an ECMAScript iterator.
It takes a String containing a whole XML document and parses it giving out a sequence of XMLNode instances.
For self enclosed tags, a pair of objects (StartElement / EndElement) is emitted.
const xml = fs.readFileSync ('small.xml', 'utf-8')
for (const node of new XMLIterator (xml, {}))
if (node.isStartElement && node.localName === 'user')
return node.attributes.get ('id') | Name | Default | Description |
|---|---|---|
| entityResolver | EntityResolver | to be used with generated XMLNodes |
XMLLexer and XMLIterator and are both low level XML parsers splitting pointy bracket delimited text to syntactically atomic tokens. But:
-
XMLLexertakes the source in the form of a Stream and represents a Transform (thus, an asynchronous iterator) designed to process documents of any size with a limited memory footprint; -
XMLIteratorrequires the source to be completely loaded in memory as a finite string, but provides the regularIteratorthat can be used in synchronous environments (e. g. in object constructors).
So, XMLLexer vs. XMLIterator is basically like fs.createReadStream vs. fs.readFileSync.