1 <html> 2 <head> 3 <link rel="stylesheet" href="../js/resources/js-test-style.css"> 4 <script src="../js/resources/js-test-pre.js"></script> 5 <script src="xpath-test-pre.js"></script> 6 </head> 7 <body> 8 <p>This tests that XPath expressions with prefixes work correctly.</p> 9 <div id="console"></div> 10 <script> 11 var xmlString = '<ns:foo xmlns:ns="http://www.example.org" xmlns:foo="urn:foobar"/>'; 12 13 var doc = (new DOMParser()).parseFromString(xmlString, "text/xml"); 14 var contextNode = doc.documentElement; 15 var nsResolver = document.createNSResolver(contextNode); 16 17 var expr = doc.createExpression("/ns:foo", nsResolver); 18 var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 19 checkSnapshot("/ns:foo", result, [doc.documentElement]); 20 21 var expr = doc.createExpression("/ns:*", nsResolver); 22 var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 23 checkSnapshot("/ns:*", result, [doc.documentElement]); 24 25 var expr = doc.createExpression("/foo:*", nsResolver); 26 var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 27 checkSnapshot("/foo:*", result, []); 28 29 // Now try a resolver originating from the function 30 var namespaces = { xmpl: "http://www.example.org" }; 31 var mapResolver = function(prefix) { return namespaces[prefix]; }; 32 33 var expr = doc.createExpression("/xmpl:*", mapResolver); 34 var result = expr.evaluate(contextNode, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 35 checkSnapshot("/xmpl:*", result, [doc.documentElement]); 36 37 var evaluator = new XPathEvaluator(); 38 var result = evaluator.evaluate("/xmpl:*", doc, mapResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); 39 checkSnapshot("/xmpl:*", result, [doc.documentElement]); 40 41 var successfullyParsed = true; 42 43 </script> 44 <script src="../js/resources/js-test-post.js"></script> 45 </body> 46 </html> 47