Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
break;
case xpath.XPathResult.STRING_TYPE:
evalResult.result = result.stringValue;
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");
});
}
const nodes = new Array();
const xdoc: Document = new DOMParser().parseFromString(xml, "text/xml");
const resolver = (xpath as any).createNSResolver(xdoc);
const xPathResult = xpath.evaluate(query, xdoc, resolver, 0, null);
const evaluatorResult = new EvaluatorResult();
evaluatorResult.type = EvaluatorResultType.SCALAR_TYPE;
switch (xPathResult.resultType) {
case XPathResultTypes.NUMBER_TYPE:
evaluatorResult.result = xPathResult.numberValue;
break;
case XPathResultTypes.STRING_TYPE:
evaluatorResult.result = xPathResult.stringValue;
break;
case XPathResultTypes.BOOLEAN_TYPE:
evaluatorResult.result = xPathResult.booleanValue;
break;
case XPathResultTypes.UNORDERED_NODE_ITERATOR_TYPE:
case XPathResultTypes.ORDERED_NODE_ITERATOR_TYPE: