/** * XmlSerializer (v1.4 update) * ────────────────────────────── * Phase 4 of the XML pipeline: converts a DOM tree back to an XML string. * * v1.4 additions * ─────────────── * • G23 — xml:space="preserve" propagation from ancestors (not just element) * • G20 — Namespace prefix control: `preferredPrefixes` map, `sortAttributes` * • Consistent attribute ordering (optional sort) * * Responsibilities * ──────────────── * • Configurable indentation * • Mixed-content detection — never re-indents mixed nodes * • xml:space="preserve" honoured at every level, including inherited * • CDATA preserved intact * • Self-closing tags for empty elements (configurable) * • XML declaration emitted optionally * • Namespace declarations preserved * • Attribute value encoding (both quotes, tab/cr/lf) * * Usage * ───── * const xml = new XmlSerializer().serialize(doc); * const xml = new XmlSerializer({ indent: 4, selfClose: false }).serialize(doc); */ import { XmlDocument, XmlElement } from './XmlNodes'; export interface SerializerOptions { /** * Number of spaces per indent level (default: 2). * Set to 0 to disable indentation (compact output). */ indent?: number; /** * Emit the XML declaration at the top (default: true). */ xmlDeclaration?: boolean; /** * Serialise empty elements as `` (default: true). * Set to false to emit `` instead. */ selfClose?: boolean; /** * Line separator string (default: '\n'). */ newline?: string; /** * G20: Map of namespace URI → preferred prefix. * When set, the serializer emits the preferred prefix instead of the * original source prefix (useful for normalising output). * Example: { 'http://www.w3.org/2001/XMLSchema': 'xs' } */ preferredPrefixes?: Record; /** * G20: Sort attributes alphabetically (default: false). * Useful for canonical output and diff-friendly serialisation. */ sortAttributes?: boolean; } export declare class XmlSerializer { private indent; private xmlDecl; private selfClose; private nl; private preferredPrefixes; private sortAttrs; constructor(options?: SerializerOptions); /** Serialize a full document including the XML declaration. */ serialize(doc: XmlDocument): string; /** Serialize a single element (no XML declaration). */ serializeElement(elem: XmlElement, indentLevel?: number): string; private _xmlDecl; private _serializeNode; private _serializeElement; /** G20: Build attribute string with optional sort and preferred prefix rewriting */ private _buildAttrString; } /** * Convenience function — serialize a document with default options. */ export declare function serializeXml(doc: XmlDocument, options?: SerializerOptions): string; //# sourceMappingURL=XmlSerializer.d.ts.map