How to use the xpath.XPathResult 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
/*
 * @package jsDAV
 * @subpackage CalDAV
 * @copyright Copyright(c) 2013 Mike de Boer. 
 * @author Oleg Elifantiev 
 * @license http://github.com/mikedeboer/jsDAV/blob/master/LICENSE MIT License
 */

"use strict";

var Base = require('./../shared/base');
var Util = require("./../shared/util");
var Exc = require("./../shared/exceptions");
var Xml = require("./../shared/xml");
var xpath = require('xpath');
var XPathResult = xpath.XPathResult;
var jsVObject_DateTimeParser = require('./../VObject/dateTimeParser');

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, {
github DotJoshJohnson / vscode-xml / src / services / XPathEvaluator.ts View on Github external
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;
                break; 
            case xpath.XPathResult.BOOLEAN_TYPE:
                evalResult.result = result.booleanValue;
                break; 
            case xpath.XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
            case xpath.XPathResult.ORDERED_NODE_ITERATOR_TYPE:
                evalResult.result = result.booleanValue;
                let node: Node;
                while (node = result.iterateNext()) {
                    nodes.push(node);
                }
                evalResult.result = nodes;
                evalResult.type = EvaluatorResultType.NODE_COLLECTION;
                break; 
        }
github DotJoshJohnson / vscode-xml / src / services / XPathEvaluator.ts View on Github external
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;
                break; 
            case xpath.XPathResult.BOOLEAN_TYPE:
                evalResult.result = result.booleanValue;
                break;
github philipmulcahy / azad / src / js / util.js View on Github external
function getXPathResult() {
    if (typeof(XPathResult) === 'undefined') {
        return xpath.XPathResult;
    }
    return XPathResult;
}

xpath

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

MIT
Latest version published 11 months ago

Package Health Score

77 / 100
Full package analysis