Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
});