@rxap/xml-parser
Version:
Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into
56 lines (55 loc) • 3.16 kB
TypeScript
export interface RxapElementOptions {
withNamespace?: boolean;
caseSensitive?: boolean;
}
/**
* Normalizes the provided node name based on the specified options.
*
* This function adjusts the `nodeName` according to the `options` provided. It can convert the node name to lowercase if `caseSensitive` is set to false. Additionally, it can remove the namespace prefix from the node name if `withNamespace` is set to false.
*
* @param {string} nodeName - The original node name to be normalized.
* @param {RxapElementOptions} options - Configuration options that determine how the node name should be normalized. The options include:
* - `caseSensitive`: A boolean that indicates whether the node name should be treated as case-sensitive. If false, the node name will be converted to lowercase.
* - `withNamespace`: A boolean that indicates whether the namespace prefix should be included in the node name. If false, any namespace prefix is removed.
* @returns {string} The normalized node name based on the provided options.
*/
export declare function normalizeNodeName(nodeName: string, options: RxapElementOptions): string;
export declare class RxapElement {
readonly element: Element;
readonly DOMParser: typeof window.DOMParser;
readonly options: RxapElementOptions;
constructor(element: Element, DOMParser: typeof window.DOMParser, options?: RxapElementOptions);
get attributes(): Record<string, string>;
get attributeNames(): string[];
get name(): string;
get nodeName(): string;
getString<T = undefined>(qualifiedName: string, defaultValue?: T): T | string;
get<D = undefined, T = any>(qualifiedName: string, defaultValue?: D, raw?: boolean): T | D;
set(qualifiedName: string, value: any): void;
hasName(name: string): boolean;
getDate(qualifiedName: string): number | undefined;
getNumber<T = undefined>(qualifiedName: string, defaultValue?: T): number | T;
getBoolean(qualifiedName: string, defaultValue?: boolean): boolean | undefined;
has(qualifiedName: string): boolean;
hasChildren(): boolean;
hasChild(nodeName: string): boolean;
getAllChildNodes(): RxapElement[];
getCountChildren(): number;
getChildren(...nodeNames: string[]): RxapElement[];
getChild(nodeName: string): RxapElement | undefined;
getTextContent<T = string>(defaultValue?: any, raw?: boolean): T;
getRawContent(): string;
removeAllChildren(): void;
setRawContent(value: string): void;
getChildRawContent(nodeName: string, defaultValue?: string): string;
setChildRawContent(nodeName: string, value: string): void;
getChildTextContent<T = string>(nodeName: string, defaultValue?: any, raw?: boolean): T;
getChildrenTextContent<T = string>(nodeName: string, defaultValue?: any): T[];
normalizeNodeName(nodeName: string): string;
appendChild(node: any | RxapElement): void;
addChild(nodeName: string): RxapElement;
setChildTextContent(nodeName: string, value: string): void;
addChildTextContent(nodeName: string, value: string): void;
setTextContent(value: string): void;
setChildren(children: RxapElement[]): void;
}