@push.rocks/smartxml
Version:
A package for creating and parsing XML formatted files.
61 lines (60 loc) • 1.51 kB
TypeScript
/**
* A lightweight chainable XML builder that provides a fluent API
* for programmatically constructing XML documents.
*/
export declare class XmlBuilder {
private stack;
private current;
private rootElement;
/**
* Creates a new XML builder instance
* @param input Optional: object to convert to XML, or XML string to parse
*/
constructor(input?: any);
/**
* Static factory method for creating instances
*/
static create(input?: any): XmlBuilder;
/**
* Add an element
* @param name Element name
* @param attributes Optional attributes object
*/
ele(name: string, attributes?: Record<string, any>): this;
/**
* Add text content to current element
* @param content Text content
*/
txt(content: string | number): this;
/**
* Add attribute to current element
* @param name Attribute name
* @param value Attribute value
*/
att(name: string, value: any): this;
/**
* Move up to parent element
*/
up(): this;
/**
* Get the root element (for navigation)
*/
root(): this;
/**
* Add a comment
* @param content Comment text
*/
com(content: string): this;
/**
* Serialize the XML document
* @param options Serialization options
*/
end(options?: {
prettyPrint?: boolean;
format?: string;
}): string | any;
/**
* Convert to string (alias for end)
*/
toString(): string;
}