Skip to content

XMLIterator

do- edited this page Oct 16, 2022 · 17 revisions

Description

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.

Usage

  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')  

Clone this wiki locally