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<div id="console"></div> 9 10<script> 11function nsResolver(prefix) { 12 if (prefix == "ns") 13 return "foobarns"; 14 if (prefix == "xml") 15 return "http://www.w3.org/XML/1998/namespace"; 16 if (prefix == "xmlns") 17 return "http://www.w3.org/2000/xmlns/"; 18 alert("Unexpected prefix " + prefix); 19} 20 21doc = (new DOMParser).parseFromString( 22 '<doc>' + 23 ' <elem attr1="1" ns:attr2="2" xml:id="3" ns:xmlns="4" xmlns:ns="foobarns" xmlns="barfoons"/>' + 24 '</doc>', 25 'application/xml'); 26 27shouldBe('doc.evaluate("//@attr1", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1'); 28shouldBe('doc.evaluate("//@attr2", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0'); 29shouldBe('doc.evaluate("//@ns:attr2", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1'); 30shouldBe('doc.evaluate("//@ns:xmlns", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1'); 31shouldThrow('doc.evaluate("//@xml:id", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength'); 32shouldBe('doc.evaluate("//@xml:id", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1'); 33shouldBe('doc.evaluate("//@*", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '4'); 34shouldBe('doc.evaluate("//@ns:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '2'); 35shouldBe('doc.evaluate("//@xml:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1'); 36shouldBe('doc.evaluate("//@xmlns", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0'); 37shouldBe('doc.evaluate("//@xmlns:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0'); 38 39var successfullyParsed = true; 40 41</script> 42<script src="../js/resources/js-test-post.js"></script> 43</body> 44</html> 45