How to use the xpath.createNSResolver function in xpath

To help you get started, we’ve selected a few xpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DotJoshJohnson / vscode-xml / src / services / XPathEvaluator.ts View on Github external
static evaluate(query: string, xml: string, ignoreDefaultNamespace: boolean): EvaluatorResult {
        if (ignoreDefaultNamespace) {
            xml = xml.replace(/xmlns=".+"/g, (match: string) => {
                return match.replace(/xmlns/g, 'xmlns:default');
        let nodes: Node[] = new Array();
        let xdoc: Document = new DOMParser().parseFromString(xml, 'text/xml');
        let resolver: xpath.XPathNSResolver = xpath.createNSResolver(xdoc);
        let result: xpath.XPathResult = xpath.evaluate(
            query,            // xpathExpression
            xdoc,                        // contextNode
            resolver,                       // namespaceResolver
            xpath.XPathResult.ANY_TYPE, // resultType
            null                        // result

        let evalResult = new EvaluatorResult();
        evalResult.type = EvaluatorResultType.SCALAR_TYPE;
        switch(result.resultType) {
            case xpath.XPathResult.NUMBER_TYPE:
                evalResult.result = result.numberValue;
            case xpath.XPathResult.STRING_TYPE:


DOM 3 XPath implemention and helper for node.js and the web

Latest version published 4 months ago

Package Health Score

81 / 100
Full package analysis