blob: d39eac3d0510bf9b9a9b1cbb1b2fa749eb2c0786 [file] [log] [blame]
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="xpath-test-pre.js"></script>
</head>
<body>
<p>This tests that XPath expressions with prefixes work correctly.</p>
<div id="console"></div>
<script>
var xmlString = '<ns:foo xmlns:ns="http://www.example.org" xmlns:foo="urn:foobar"/>';
var doc = (new DOMParser()).parseFromString(xmlString, "text/xml");
var contextNode = doc.documentElement;
var nsResolver = document.createNSResolver(contextNode);
var expr = doc.createExpression("/ns:foo", nsResolver);
var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("/ns:foo", result, [doc.documentElement]);
var expr = doc.createExpression("/ns:*", nsResolver);
var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("/ns:*", result, [doc.documentElement]);
var expr = doc.createExpression("/foo:*", nsResolver);
var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("/foo:*", result, []);
// Now try a resolver originating from the function
var namespaces = { xmpl: "http://www.example.org" };
var mapResolver = function(prefix) { return namespaces[prefix]; };
var expr = doc.createExpression("/xmpl:*", mapResolver);
var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("/xmpl:*", result, [doc.documentElement]);
var evaluator = new XPathEvaluator();
var result = evaluator.evaluate("/xmpl:*", doc, mapResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
checkSnapshot("/xmpl:*", result, [doc.documentElement]);
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>