diff --git a/types/libxmljs/index.d.ts b/types/libxmljs/index.d.ts index 7fc9e9e2bf..4305c662a8 100644 --- a/types/libxmljs/index.d.ts +++ b/types/libxmljs/index.d.ts @@ -12,16 +12,14 @@ export const libxml_version: string; export const libxml_parser_version: string; // tslint:disable-next-line:strict-export-declare-modifiers -interface ParseOptions { - [optionName: string]: string; -} +interface StringMap { [key: string]: string; } -export function parseXml(source: string, options?: ParseOptions): Document; -export function parseXmlString(source: string, options?: ParseOptions): Document; +export function parseXml(source: string, options?: StringMap): Document; +export function parseXmlString(source: string, options?: StringMap): Document; -export function parseHtml(source: string, options?: ParseOptions): Document; -export function parseHtmlString(source: string, options?: ParseOptions): Document; -export function parseHtmlFragment(source: string, options?: ParseOptions): Document; +export function parseHtml(source: string, options?: StringMap): Document; +export function parseHtmlString(source: string, options?: StringMap): Document; +export function parseHtmlFragment(source: string, options?: StringMap): Document; export function memoryUsage(): number; export function nodeCount(): number; @@ -41,7 +39,7 @@ export class Document { encoding(): string; encoding(enc: string): this; find(xpath: string): Element[]; - get(xpath: string): Element|null; + get(xpath: string, namespaces?: StringMap): Element|null; node(name: string, content?: string): Element; root(): Element|null; root(newRoot: Node): Node; @@ -98,7 +96,7 @@ export class Element extends Node { text(): string; text(newText: string): this; attr(name: string): Attribute|null; - attr(attrObject: { [key: string]: string; }): this; + attr(attrObject: StringMap): this; attrs(): Attribute[]; doc(): Document; @@ -115,7 +113,7 @@ export class Element extends Node { addNextSibling(siblingNode: Node): Node; find(xpath: string, ns_uri?: string): Node[]; - find(xpath: string, namespaces: { [key: string]: string; }): Node[]; + find(xpath: string, namespaces: StringMap): Node[]; get(xpath: string, ns_uri?: string): Element|null; defineNamespace(prefixOrHref: string, hrefInCaseOfPrefix?: string): Namespace; diff --git a/types/libxmljs/libxmljs-tests.ts b/types/libxmljs/libxmljs-tests.ts index 367d74c69d..fe720cc242 100644 --- a/types/libxmljs/libxmljs-tests.ts +++ b/types/libxmljs/libxmljs-tests.ts @@ -47,3 +47,18 @@ const doc = new libxmljs.Document(); .node('sibling', 'with content!'); const {name, externalId, systemId} = doc.getDtd(); + +const xmlWithNs = '' + + '' + + '' + + 'grandchild content' + + '' + + 'with content!' + + ''; + +const xmlDocWithNs = libxmljs.parseXml(xmlWithNs); + +// xpath queries +const gchildWithNs = xmlDocWithNs.get('//a:grandchild', {a: 'http://test.com/test'})!; + +console.log(gchildWithNs.text()); // prints "grandchild content"