/** * XmlWriter - Non-Streaming XML Builder * * Builds XML as an in-memory string. Implements the {@link XmlSink} interface * so rendering code can target either this or {@link XmlStreamWriter}. * * Uses array-based buffering (push + join) for O(n) concatenation performance, * with rollback support via snapshot/restore. */ import { StdDocAttributes } from "./encode.js"; import type { XmlAttributes, XmlSink } from "./types.js"; /** * Non-streaming XML writer that builds a complete XML string in memory. * * @example * ```ts * const w = new XmlWriter(); * w.openXml(); * w.openNode("root", { version: "1.0" }); * w.leafNode("child", { id: "1" }, "text"); * w.closeNode(); * console.log(w.toString()); * // * // text * ``` */ declare class XmlWriter implements XmlSink { private _parts; private _chunks; private _stack; private _snapshots; private _leaf; private _open; /** Periodically consolidate small strings to reduce final join overhead. */ private _consolidate; /** Current nesting depth (number of open elements). */ get depth(): number; /** Name of the innermost open element, or undefined if none. */ get currentElement(): string | undefined; /** * Monotonic cursor that tracks how much content has been written. * Useful for detecting whether a section produced any output. */ get cursor(): number; openXml(attributes?: XmlAttributes): void; openNode(name: string, attributes?: XmlAttributes): void; addAttribute(name: string, value: string | number | boolean): void; addAttributes(attributes: XmlAttributes): void; writeText(text: string | number): void; writeRaw(xml: string): void; writeCData(text: string): void; writeComment(text: string): void; closeNode(): void; leafNode(name: string, attributes?: XmlAttributes, text?: string | number): void; /** Close all open elements. */ closeAll(): void; /** Return the built XML string. */ toString(): string; /** Alias for toString(). */ get xml(): string; /** * Save a snapshot of the current writer state. * Call {@link commit} to discard the snapshot or {@link rollback} to restore it. * * Snapshots can be nested. */ save(): void; /** Discard the most recent snapshot (keep current state). */ commit(): void; /** Restore to the most recent snapshot (discard changes since save). */ rollback(): void; /** Reset the writer to its initial empty state. */ reset(): void; } export { XmlWriter, StdDocAttributes };