edockit
Version:
A JavaScript library for listing, parsing, and verifying the contents and signatures of electronic documents (eDoc) and Associated Signature Containers (ASiC-E), supporting EU eIDAS standards for digital signatures and electronic seals.
76 lines (75 loc) • 3.29 kB
TypeScript
/**
* Recursive DOM traversal to find elements with a given tag name
* (Fallback method when XPath is not available or fails)
*
* @param parent The parent element to search within
* @param selector CSS-like selector with namespace support (e.g., "ds:SignedInfo, SignedInfo")
* @returns Array of matching elements
*/
export declare function findElementsByTagNameRecursive(parent: Node, selector: string): Element[];
/**
* A cross-environment XML parser that works in both Node.js and browsers
* with enhanced XPath support for handling namespaced elements
*/
export interface XMLParserInterface {
parseFromString(text: string, mimeType: string): Document;
}
export type NamespaceMap = Record<string, string>;
export declare const NAMESPACES: NamespaceMap;
/**
* Create an XML parser that works in both browser and Node environments
*/
export declare function createXMLParser(): XMLParserInterface;
/**
* Uses XPath to find a single element in an XML document
*
* @param parent The parent element or document to search within
* @param xpathExpression The XPath expression to evaluate
* @param namespaces Optional namespace mapping (defaults to common XML signature namespaces)
* @returns The found element or null
*/
export declare function queryByXPath(parent: Document | Element, xpathExpression: string, namespaces?: NamespaceMap): Element | null;
/**
* Uses XPath to find all matching elements in an XML document
*
* @param parent The parent element or document to search within
* @param xpathExpression The XPath expression to evaluate
* @param namespaces Optional namespace mapping (defaults to common XML signature namespaces)
* @returns Array of matching elements
*/
export declare function queryAllByXPath(parent: Document | Element, xpathExpression: string, namespaces?: NamespaceMap): Element[];
/**
* Converts a CSS-like selector (with namespace support) to an XPath expression
*
* @param selector CSS-like selector (e.g., "ds:SignedInfo, SignedInfo")
* @returns Equivalent XPath expression
*/
export declare function selectorToXPath(selector: string): string;
/**
* Enhanced querySelector that uses XPath for better namespace handling
* (Drop-in replacement for the original querySelector function)
*
* @param parent The parent element or document to search within
* @param selector A CSS-like selector (with namespace handling)
* @returns The found element or null
*/
export declare function querySelector(parent: Document | Element, selector: string): Element | null;
/**
* Enhanced querySelectorAll that uses XPath for better namespace handling
* (Drop-in replacement for the original querySelectorAll function)
*
* @param parent The parent element or document to search within
* @param selector A CSS-like selector (with namespace handling)
* @returns Array of matching elements
*/
export declare function querySelectorAll(parent: Document | Element, selector: string): Element[];
/**
* Serialize a DOM node to XML string
*/
export declare function serializeToXML(node: Node): string;
/**
* Debug function to print XML structure for troubleshooting
* @param node The root node to debug
* @param depth Current depth (used for indentation)
*/
export declare function debugXmlStructure(node: Node, depth?: number): void;