/** * XmlToJson — XML → JSON conversion * ─────────────────────────────────── * Converts an XmlDocument or XmlElement into a plain JavaScript object / * JSON-serialisable value. * * Conversion rules * ──────────────── * • Element with text-only children → { tag: string, _text: string, ...attrs } * • Element with element children → { tag: string, children: [...], ...attrs } * • Attributes are hoisted to the same level with '@' prefix by default * • Multiple sibling elements with the same tag are collected into arrays * • CDATA sections are treated the same as text nodes * • Comments and processing instructions are skipped by default * * Usage * ───── * import { xmlToJson } from 'xml-xsd-engine/transform'; * * const obj = xmlToJson(doc); * const json = JSON.stringify(obj, null, 2); */ import { XmlDocument, XmlElement } from '../parser/XmlNodes'; export interface XmlToJsonOptions { /** * Prefix for attribute keys in the output object. * Default: '@' (e.g. attribute "id" becomes "@id") * Set to '' to omit prefix. */ attributePrefix?: string; /** * Key used for text content when an element also has attributes or * element children. Default: '_text' */ textKey?: string; /** * Whether to include XML comments in the output. Default: false */ includeComments?: boolean; /** * When true, an element with a single text child is collapsed to a plain * string value instead of an object. Default: true * * e.g. Alice → "Alice" (not { _text: "Alice" }) */ collapseText?: boolean; /** * When true, numeric-looking text values are coerced to numbers. * Default: false */ coerceNumbers?: boolean; /** * When true, "true"/"false" text values are coerced to booleans. * Default: false */ coerceBooleans?: boolean; /** * Whether to include the element tag name in the output object. * Default: false (tag name is the key in the parent object) */ includeTagName?: boolean; } export type JsonValue = string | number | boolean | null | JsonObject | JsonValue[]; export interface JsonObject { [key: string]: JsonValue; } /** * Convert an XmlDocument or XmlElement into a JSON-serialisable object. */ export declare function xmlToJson(node: XmlDocument | XmlElement, options?: XmlToJsonOptions): JsonObject; //# sourceMappingURL=XmlToJson.d.ts.map