Skip to content

SAXEvent

do- edited this page Nov 21, 2021 · 21 revisions

Instances of this class represent SAX (or StAX) style events.

They encapsulate distinct chunks of source XML text, normally given away by XMLLexer.

Usage

const e = new SAXEvent (chunk)

if (e.type === SAXEvent.TYPES.START_ELEMENT && e.isSelfEnclosing)
  console.log (e.attributes)

Methods

Name, Parameters Return Value Description
get type SAXEvent.TYPES.* Lazy getter for the event type
get attributes Map Lazy getter for the Map of attributes
get text string substring for CDATA, src otherwise
isSelfEnclosing () Boolean true iif the penultimate character is /

Members

Name Type Description
src string The original string, unparsed
_afterName int For element tags, some position after the name, before the first attribute (if any)

Event types

This list is loosely based on JSR-000173.

Event Name Public Variable Name Description Note
StartDocument SAXEvent.TYPES.START_DOCUMENT <?xml ...?>, case insensitive In real world XML, MAY NOT OCCUR AT ALL
ProcessingInstruction SAXEvent.TYPES.PROCESSING_INSTRUCTION any other <?...?>
Comment SAXEvent.TYPES.COMMENT <!-- ... -->
DTD SAXEvent.TYPES.DTD <!DOCTYPE ...>
StartElement SAXEvent.TYPES.START_ELEMENT <not-a-slash ...>
CDATA SAXEvent.TYPES.CDATA <![CDATA[...]]> As SAXEvent.type, distinct from SAXEvent.TYPES.CHARACTERS
EndElement SAXEvent.TYPES.END_ELEMENT </...>
Characters SAXEvent.TYPES.CHARACTERS any text without pointy braces around it
EndDocument SAXEvent.TYPES.END_DOCUMENT never occurs Included here to complete the SAXEventEmitter functionality

Clone this wiki locally