* Finalize parsing and validate that all elements are closed. * * @throws {XmlSyntaxError} If there are unclosed elements or no root element.
()
| 680 | * @throws {XmlSyntaxError} If there are unclosed elements or no root element. |
| 681 | */ |
| 682 | finalize(): void { |
| 683 | if (this.#elementStack.length > 0) { |
| 684 | const unclosed = this.#elementStack[this.#elementStack.length - 1]!; |
| 685 | throw new XmlSyntaxError( |
| 686 | `Unclosed element <${unclosed.rawName}>`, |
| 687 | unclosed, |
| 688 | ); |
| 689 | } |
| 690 | |
| 691 | // XML 1.0 §2.1: A well-formed document must have exactly one root element |
| 692 | if (!this.#hasRoot) { |
| 693 | throw new XmlSyntaxError( |
| 694 | "No root element found in XML document", |
| 695 | { line: 0, column: 0, offset: 0 }, |
| 696 | ); |
| 697 | } |
| 698 | } |
| 699 | } |
no outgoing calls
no test coverage detected