How to use the xpath.createExpression 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 mikedeboer / jsDAV / lib / CalDAV / calendarQueryParser.js View on Github external
function xSelect(expr, doc, single) {

    var nodesWithXMLNS = xpath.select("//@*[starts-with(name(), 'xmlns:')]", doc);
    var revmap = {};

    for(var i = 0, l = nodesWithXMLNS.length; i < l; i++) {
        var node = nodesWithXMLNS[i];

        revmap[node.nodeName.substr(6)] = node.nodeValue;
    }

    // FIXME THIS IS UGLY!
    var expression = xpath.createExpression(expr, {

        lookupNamespaceURI: function(short) {
            if(short in revmap) {
                return revmap[short];
            }
            for(var fullNs in Xml.xmlNamespaces) {
                if(Xml.xmlNamespaces.hasOwnProperty(fullNs)) {
                    if(Xml.xmlNamespaces[fullNs] == short) {
                        revmap[short] = fullNs;
                        return fullNs;
                    }
                }
            }
            return null;
        }
    });

xpath

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

MIT
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis