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.isSelfEnclosed)
  console.log (e.attributes)

Computed properties

Name, Parameters Return Value Description
type SAXEvent.TYPES.* Getter for the event type
attributes Map Lazy getter for the Map of attributes
text string src.slice (9, -3) iif the first character is < (for CDATA it's the body text), src otherwise
isSelfEnclosed 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