1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml" > 3 <head> 4 <title>Namespace Resolver Test Case</title> 5 </head> 6 <body> 7 <div id="result">FAILURE</div> 8 <script type="text/javascript"><![CDATA[ 9 if (window.layoutTestController) 10 layoutTestController.dumpAsText(); 11 12 function MyNSResolver() {} 13 MyNSResolver.prototype.lookupNamespaceURI = function(prefix) { 14 switch (prefix) { 15 case "foo": 16 return "http://www.example.com"; 17 break; 18 default: 19 return null; 20 break; 21 } 22 } 23 24 var sXml = "<root><ex:child xmlns:ex='http://www.example.com'>SUCCESS</ex:child></root>"; 25 var oXmlDom = (new DOMParser()).parseFromString(sXml, "text/xml"); 26 27 try { 28 29 var oResult = oXmlDom.evaluate("foo:child/text()", oXmlDom.documentElement, new MyNSResolver, 30 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null); 31 32 document.getElementById("result").textContent = oResult.iterateNext().nodeValue; 33 34 } catch (ex) { 35 document.getElementById("result").textContent = ex; 36 } 37 ]]></script> 38 39 </body> 40 </html> 41