expat-wasm
    Preparing search index...

    Class XmlParser

    An evented parser based on a WASM-compiled version of expat. NOTE: Please make sure to call destroy() when you are done, or ensure that you have used using to get explicit resource disposal (if that is supported in your environment).

    XmlParser

    Hierarchy

    • EventEmitter
      • XmlParser

    Indexable

    • [key: symbol]: () => void
    Index

    Constructors

    • Create a parser instance.

      Parameters

      • Optionalencoding: XML_Encoding | ParserOptions

        null will do content sniffing. If an object, extended parser options, and the second parameter is ignored.

      • Optionalseparator: string | symbol = '|'

        the separator for namespace URI and element/attribute name. Use XmlParser.NO_NAMESPACES to get Expat's old, broken namespace non-implementation via XmlParserCreate instead of XmlParserCreateNS.

      Returns XmlParser

    Properties

    CHUNK_SIZE: number = 4096
    NO_NAMESPACES: symbol = ...

    Use as the separator to treat namespaces in legacy mode.

    opts: Required<ParserOptions>

    Methods

    • Returns a string describing the error.

      Parameters

      • code: number

      Returns string

      Error description in English.

    • Returns string

      Current expat version number.

    • Creates an XML_Parser object that can parse an external general entity; context is a '\0'-terminated string specifying the parse context; encoding is a '\0'-terminated string giving the name of the externally specified encoding, or NULL if there is no externally specified encoding. The context string consists of a sequence of tokens separated by formfeeds (\f); a token consisting of a name specifies that the general entity of the name is open; a token of the form prefix=uri specifies the namespace for a particular prefix; a token of the form =uri specifies the default namespace. This can be called at any point after the first call to an ExternalEntityRefHandler so longer as the parser has not yet been freed. The new parser is completely independent and may safely be used in a separate thread. The handlers and userData are initialized from the parser argument. Returns NULL if out of memory. Otherwise returns a new XML_Parser object.

      Parameters

      Returns any

    • Function to deallocate the model argument passed to the XML_ElementDeclHandler callback set using XML_ElementDeclHandler.

      Parameters

      • parser: number
      • model: number

      Returns void

    • Get the base URI from a parser.

      Parameters

      • parser: number

      Returns string

    • These functions return information about the current parse location. They may be called from any callback called to report some parse event; in this case the location is the location of the first of the sequence of characters that generated the event. When called from callbacks generated by declarations in the document prologue, the location identified isn't as neatly defined, but will be within the relevant markup. When called outside of the callback functions, the position indicated will be just past the last parse event (regardless of whether there was an associated callback).

      They may also be called after returning from a call to XML_Parse or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then the location is the location of the character at which the error was detected; otherwise the location is the location of the last parse event, as described above.

      Parameters

      • parser: number

      Returns number

      -1 on error, or byte offset.

    • These functions return information about the current parse location. They may be called from any callback called to report some parse event; in this case the location is the location of the first of the sequence of characters that generated the event. When called from callbacks generated by declarations in the document prologue, the location identified isn't as neatly defined, but will be within the relevant markup. When called outside of the callback functions, the position indicated will be just past the last parse event (regardless of whether there was an associated callback).

      They may also be called after returning from a call to XML_Parse or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then the location is the location of the character at which the error was detected; otherwise the location is the location of the last parse event, as described above.

      Parameters

      • parser: number

      Returns number

      0 on error, or column number.

    • These functions return information about the current parse location. They may be called from any callback called to report some parse event; in this case the location is the location of the first of the sequence of characters that generated the event. When called from callbacks generated by declarations in the document prologue, the location identified isn't as neatly defined, but will be within the relevant markup. When called outside of the callback functions, the position indicated will be just past the last parse event (regardless of whether there was an associated callback).

      They may also be called after returning from a call to XML_Parse or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then the location is the location of the character at which the error was detected; otherwise the location is the location of the last parse event, as described above.

      Parameters

      • parser: number

      Returns number

      0 on error, or line number.

    • If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then XML_GetErrorCode returns information about the error.

      Parameters

      • parser: number

      Returns number

      Error code

    • The user data is the first four bytes of the parser struct. #define XML_GetUserData(parser) (*(void **)(parser))

      Parameters

      • parser: number

      Returns number

      User data

    • Parse some more of the document. The string s is a buffer containing part (or perhaps all) of the document. The number of bytes of s that are part of the document is indicated by len. This means that s doesn't have to be null terminated. It also means that if len is larger than the number of bytes in the block of memory that s points at, then a memory fault is likely. The isFinal parameter informs the parser that this is the last piece of the document. Frequently, the last piece is empty (i.e. len is zero.) If a parse error occurred, it returns XML_STATUS_ERROR. Otherwise it returns XML_STATUS_OK value.

      Parameters

      • parser: number
      • str:
            | string
            | Buffer<ArrayBufferLike>
            | Uint8Array<ArrayBufferLike>
            | Uint8ClampedArray<ArrayBufferLike>
      • isFinal: number
      • encoding: BufferEncoding

      Returns number

      ERROR=0, OK=1, SUSPENDED=2

    • Construct a new parser. If encoding is non-null, it specifies a character encoding to use for the document. This overrides the document encoding declaration. There are four built-in encodings:

      • US-ASCII
      • UTF-8
      • UTF-16
      • ISO-8859-1 Any other value will invoke a call to the UnknownEncodingHandler.

      Parameters

      Returns number

      Parser pointer

    • Constructs a new parser that has namespace processing in effect. Namespace expanded element names and attribute names are returned as a concatenation of the namespace URI, sep, and the local part of the name. This means that you should pick a character for sep that can't be part of an URI. Since Expat does not check namespace URIs for conformance, the only safe choice for a namespace separator is a character that is illegal in XML. For instance, '\xFF' is not legal in UTF-8, and '\xFFFF' is not legal in UTF-16. There is a special case when sep is the null character '\0': the namespace URI and the local part will be concatenated without any separator - this is intended to support RDF processors. It is a programming error to use the null separator with namespace triplets.

      Note: Expat does not validate namespace URIs (beyond encoding) against RFC 3986 today (and is not required to do so with regard to the XML 1.0 namespaces specification) but it may start doing that in future releases. Before that, an application using Expat must be ready to receive namespace URIs containing non-URI characters.

      Parameters

      • encoding: XML_Encoding
      • sep: number

        The ASCII number value of the separator character

      Returns number

      The created parser

    • Free memory used by the parser. Your application is responsible for freeing any memory associated with user data.

      Parameters

      • parser: number

      Returns void

    • Prepare a parser object to be re-used. This is particularly valuable when memory allocation overhead is disproportionately high, such as when a large number of small documnents need to be parsed. All handlers are cleared from the parser, except for the unknownEncodingHandler. The parser's external state is re-initialized except for the values of ns and ns_triplets.

      Parameters

      Returns number

      Undocumented

    • Set the base URI for including external entities.

      Parameters

      • parser: number
      • base: string

      Returns number

      1 on success, 0 on error

    • Controls parsing of parameter entities (including the external DTD subset). If parsing of parameter entities is enabled, then references to external parameter entities (including the external DTD subset) will be passed to the handler set with XML_SetExternalEntityRefHandler. The context passed will be 0. Unlike external general entities, external parameter entities can only be parsed synchronously. If the external parameter entity is to be parsed, it must be parsed during the call to the external entity ref handler: the complete sequence of XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during this call. After XML_ExternalEntityParserCreate has been called to create the parser for the external parameter entity (context must be 0 for this call), it is illegal to make any calls on the old parser until XML_ParserFree has been called on the newly created parser. If the library has been compiled without support for parameter entity parsing (ie without XML_DTD being defined), then XML_SetParamEntityParsing will return 0 if parsing of parameter entities is requested; otherwise it will return non-zero. Note: If XML_SetParamEntityParsing is called after XML_Parse or XML_ParseBuffer, then it has no effect and will always return 0. Note: If parser == NULL, the function will do nothing and return 0.

      Parameters

      • parser: number
      • parsing: number

        NEVER=0, UNLESS_STANDALONE=1, ALWAYS=2. If you want to turn this on, you probably want 1.

      Returns number

      0 on failure

    • This function only has an effect when using a parser created with XML_ParserCreateNS, i.e. when namespace processing is in effect. The doNst flag sets whether or not prefixes are returned with names qualified with a namespace prefix. If this function is called with doNst non-zero, then afterwards namespace qualified names (that is qualified with a prefix as opposed to belonging to a default namespace) are returned as a triplet with the three parts separated by the namespace separator specified when the parser was created. The order of returned parts is URI, local name, and prefix.

      If doNst is zero, then namespaces are reported in the default manner, URI then local_name separated by the namespace separator.

      Parameters

      • parser: number
      • doNst: number

      Returns void

    • This value is passed as the userData argument to callbacks.

      Parameters

      • parser: number
      • userData: number

      Returns void

    • Stop the current parser.

      Parameters

      • parser: number
      • Optionalresumable: number = 0

        1 if resumable

      Returns number

      0 on fail, 1 on success

    • The Symbol.for('nodejs.rejection') method is called in case a promise rejection happens when emitting an event and captureRejections is enabled on the emitter. It is possible to use events.captureRejectionSymbol in place of Symbol.for('nodejs.rejection').

      import { EventEmitter, captureRejectionSymbol } from 'node:events';

      class MyClass extends EventEmitter {
      constructor() {
      super({ captureRejections: true });
      }

      [captureRejectionSymbol](err, event, ...args) {
      console.log('rejection happened for', event, 'with', err, ...args);
      this.destroy(err);
      }

      destroy(err) {
      // Tear the resource down here.
      }
      }

      Parameters

      • error: Error
      • event: string | symbol
      • ...args: any[]

      Returns void

      v13.4.0, v12.16.0

    • Alias for emitter.on(eventName, listener).

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E
      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

      Returns this

      v0.1.26

    • Clean up after the parser. REQUIRED, since there is not currently memory management for WASM code.

      Returns boolean

      True if this is the first time destroy() was called.

    • Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

      Returns true if the event had listeners, false otherwise.

      import { EventEmitter } from 'node:events';
      const myEmitter = new EventEmitter();

      // First listener
      myEmitter.on('event', function firstListener() {
      console.log('Helloooo! first listener');
      });
      // Second listener
      myEmitter.on('event', function secondListener(arg1, arg2) {
      console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
      });
      // Third listener
      myEmitter.on('event', function thirdListener(...args) {
      const parameters = args.join(', ');
      console.log(`event with parameters ${parameters} in third listener`);
      });

      console.log(myEmitter.listeners('event'));

      myEmitter.emit('event', 1, 2, 3, 4, 5);

      // Prints:
      // [
      // [Function: firstListener],
      // [Function: secondListener],
      // [Function: thirdListener]
      // ]
      // Helloooo! first listener
      // event with parameters 1, 2 in second listener
      // event with parameters 1, 2, 3, 4, 5 in third listener

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | E
            | (keyof EventEmitterEventMap)
      • ...args: E extends keyof XmlEvents
            ? XmlEvents[E]
            : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[]

      Returns boolean

      v0.1.26

    • Returns an array listing the events for which the emitter has registered listeners.

      import { EventEmitter } from 'node:events';

      const myEE = new EventEmitter();
      myEE.on('foo', () => {});
      myEE.on('bar', () => {});

      const sym = Symbol('symbol');
      myEE.on(sym, () => {});

      console.log(myEE.eventNames());
      // Prints: [ 'foo', 'bar', Symbol(symbol) ]

      Returns (string | symbol)[]

      v6.0.0

    • Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to events.defaultMaxListeners.

      Returns number

      v1.0.0

    • Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

        The name of the event being listened for

      • Optionallistener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

        The event handler function

      Returns number

      v3.2.0

    • Returns a copy of the array of listeners for the event named eventName.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });
      console.log(util.inspect(server.listeners('connection')));
      // Prints: [ [Function] ]

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

      Returns (
          (
              ...args: E extends keyof XmlEvents
                  ? XmlEvents[E]
                  : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
          ) => void
      )[]

      v0.1.26

    • Alias for emitter.removeListener().

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E
      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

      Returns this

      v10.0.0

    • Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

      server.on('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.on('foo', () => console.log('a'));
      myEE.prependListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

        The name of the event.

      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

        The callback function

      Returns this

      v0.1.101

    • Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

      server.once('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

      import { EventEmitter } from 'node:events';
      const myEE = new EventEmitter();
      myEE.once('foo', () => console.log('a'));
      myEE.prependOnceListener('foo', () => console.log('b'));
      myEE.emit('foo');
      // Prints:
      // b
      // a

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

        The name of the event.

      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

        The callback function

      Returns this

      v0.3.0

    • Parse a chunk of text. If this is not the last (or only) chunk, set final to 0.

      Parameters

      • chunk:
            | string
            | Buffer<ArrayBufferLike>
            | Uint8Array<ArrayBufferLike>
            | Uint8ClampedArray<ArrayBufferLike>

        Input text

      • Optionalfinal: number = 1

        0 if not the last or only chunk.

      Returns number

    • Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

      server.prependListener('connection', (stream) => {
      console.log('someone connected!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

        The name of the event.

      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

        The callback function

      Returns this

      v6.0.0

    • Adds a one-time listener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

      server.prependOnceListener('connection', (stream) => {
      console.log('Ah, we have our first user!');
      });

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

        The name of the event.

      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

        The callback function

      Returns this

      v6.0.0

    • Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

      import { EventEmitter } from 'node:events';
      const emitter = new EventEmitter();
      emitter.once('log', () => console.log('log once'));

      // Returns a new Array with a function `onceWrapper` which has a property
      // `listener` which contains the original listener bound above
      const listeners = emitter.rawListeners('log');
      const logFnWrapper = listeners[0];

      // Logs "log once" to the console and does not unbind the `once` event
      logFnWrapper.listener();

      // Logs "log once" to the console and removes the listener
      logFnWrapper();

      emitter.on('log', () => console.log('log persistently'));
      // Will return a new Array with a single function bound by `.on()` above
      const newListeners = emitter.rawListeners('log');

      // Logs "log persistently" twice
      newListeners[0]();
      emitter.emit('log');

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

      Returns (
          (
              ...args: E extends keyof XmlEvents
                  ? XmlEvents[E]
                  : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
          ) => void
      )[]

      v9.4.0

    • Removes all listeners, or those of the specified eventName.

      It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • OptionaleventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E

      Returns this

      v0.1.26

    • Removes the specified listener from the listener array for the event named eventName.

      const callback = (stream) => {
      console.log('someone connected!');
      };
      server.on('connection', callback);
      // ...
      server.removeListener('connection', callback);

      removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

      Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events behave as expected.

      import { EventEmitter } from 'node:events';
      class MyEmitter extends EventEmitter {}
      const myEmitter = new MyEmitter();

      const callbackA = () => {
      console.log('A');
      myEmitter.removeListener('event', callbackB);
      };

      const callbackB = () => {
      console.log('B');
      };

      myEmitter.on('event', callbackA);

      myEmitter.on('event', callbackB);

      // callbackA removes listener callbackB but it will still be called.
      // Internal listener array at time of emit [callbackA, callbackB]
      myEmitter.emit('event');
      // Prints:
      // A
      // B

      // callbackB is now removed.
      // Internal listener array [callbackA]
      myEmitter.emit('event');
      // Prints:
      // A

      Because listeners are managed using an internal array, calling this will change the position indexes of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

      When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:

      import { EventEmitter } from 'node:events';
      const ee = new EventEmitter();

      function pong() {
      console.log('pong');
      }

      ee.on('ping', pong);
      ee.once('ping', pong);
      ee.removeListener('ping', pong);

      ee.emit('ping');
      ee.emit('ping');

      Returns a reference to the EventEmitter, so that calls can be chained.

      Type Parameters

      • E extends string | symbol

      Parameters

      • eventName:
            | "comment"
            | "endCdataSection"
            | "endDoctypeDecl"
            | "endElement"
            | "endNamespaceDecl"
            | "notationDecl"
            | "processingInstruction"
            | "startCdataSection"
            | "startNamespaceDecl"
            | "star"
            | "attlistDecl"
            | "characterData"
            | "default"
            | "elementDecl"
            | "endBase"
            | "entityDecl"
            | "error"
            | "skippedEntity"
            | "startBase"
            | "startDoctypeDecl"
            | "startElement"
            | "xmlDecl"
            | "destroy"
            | (keyof EventEmitterEventMap)
            | E
      • listener: (
            ...args: E extends keyof XmlEvents
                ? XmlEvents[E]
                : E extends keyof EventEmitterEventMap ? EventEmitterEventMap[E] : any[],
        ) => void

      Returns this

      v0.1.26

    • Reset the parser state, so that a new document can be parsed.

      Returns void

    • By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

      Returns a reference to the EventEmitter, so that calls can be chained.

      Parameters

      • n: number

      Returns this

      v0.3.5

    • Stop parsing in the middle of a document, usually from an event handler.

      Parameters

      • Optionalresumable: number = 0

        1 for resumable

      Returns void

    • Parse an element or attribute name.

      Parameters

      • name: string

        a EVENTS name, or a URI+local+prefix triple

      Returns Pieces

      pieces - the pieces of the name