| 130 | * streaming from tokenizer through parser to consumer. |
| 131 | */ |
| 132 | export class XmlEventParser implements XmlTokenCallbacks { |
| 133 | #callbacks: XmlEventCallbacks; |
| 134 | #ignoreWhitespace: boolean; |
| 135 | #ignoreComments: boolean; |
| 136 | #ignoreProcessingInstructions: boolean; |
| 137 | #coerceCDataToText: boolean; |
| 138 | #maxDepth: number; |
| 139 | #maxAttributes: number; |
| 140 | #xml11: boolean; |
| 141 | |
| 142 | #elementStack: Array<{ |
| 143 | rawName: string; |
| 144 | colonIndex: number; |
| 145 | uri: string | undefined; |
| 146 | line: number; |
| 147 | column: number; |
| 148 | offset: number; |
| 149 | }> = []; |
| 150 | |
| 151 | /** Track whether root element has been seen and closed */ |
| 152 | #hasRoot = false; |
| 153 | #rootClosed = false; |
| 154 | |
| 155 | // Note: We do NOT expand custom entities from DTD. |
| 156 | // Only predefined entities (lt, gt, amp, apos, quot) are supported. |
| 157 | // External entities (SYSTEM/PUBLIC) are also not supported. |
| 158 | |
| 159 | /** Pending element state (reused across elements). */ |
| 160 | #pendingName = ""; |
| 161 | #pendingColonIndex = -1; |
| 162 | #pendingLine = 0; |
| 163 | #pendingColumn = 0; |
| 164 | #pendingOffset = 0; |
| 165 | #hasPendingElement = false; |
| 166 | |
| 167 | /** Reusable attribute iterator. */ |
| 168 | #attrIterator = new AttributeIteratorImpl(); |
| 169 | |
| 170 | /** Namespace tracking (lazy initialization for performance) */ |
| 171 | #nsBindings: Map<string, string> | null = null; |
| 172 | /** Stack of namespace bindings per element scope */ |
| 173 | #nsStack: Array<Array<[string, string | undefined]>> = []; |
| 174 | /** Pending namespace bindings for current element */ |
| 175 | #pendingNsBindings: Array<[string, string | undefined]> = []; |
| 176 | |
| 177 | constructor( |
| 178 | callbacks: XmlEventCallbacks, |
| 179 | options: ParseStreamOptions = {}, |
| 180 | xml11: boolean = false, |
| 181 | ) { |
| 182 | this.#callbacks = callbacks; |
| 183 | this.#ignoreWhitespace = options.ignoreWhitespace ?? false; |
| 184 | this.#ignoreComments = options.ignoreComments ?? false; |
| 185 | this.#ignoreProcessingInstructions = options.ignoreProcessingInstructions ?? |
| 186 | false; |
| 187 | this.#coerceCDataToText = options.coerceCDataToText ?? false; |
| 188 | this.#maxDepth = options.maxDepth ?? Infinity; |
| 189 | this.#maxAttributes = options.maxAttributes ?? Infinity; |
nothing calls this directly
no outgoing calls
no test coverage detected