-
Notifications
You must be signed in to change notification settings - Fork 3
SAXEvent
do- edited this page Nov 27, 2021
·
20 revisions
Instances of this class represent SAX (or StAX) style events.
They encapsulate distinct chunks of source XML text, normally given away by XMLLexer.
const e = new SAXEvent (chunk)
if (e.type === SAXEvent.TYPES.START_ELEMENT && e.isSelfEnclosed)
console.log (e.attributes)
Name | Return Value | Description |
---|---|---|
type | SAXEvent.TYPES.* | Getter for the event type |
name | string | For StartElement and EndElement , the raw element name (maybe with namespace prefix) |
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 /
|
Name, Parameters | Return Value | Description |
---|---|---|
writeAttributesToMap (map) | Fills in the provided map with raw attributes content. To decode entities etc., use AttributesMap
|
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) |
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 |