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> 11 var doc = (new DOMParser).parseFromString( 12 '<doc>' + 13 '<item id="1" color="red" />' + 14 '<chapter id="c1">' + 15 '<item id="2" color="blue" />' + 16 '</chapter>' + 17 '</doc>', 18 'application/xml'); 19 20 var ROOT = doc.documentElement; 21 var DI1 = ROOT.firstChild; 22 var DC1 = DI1.nextSibling; 23 var DI2 = DC1.firstChild; 24 25 var docns = (new DOMParser).parseFromString( 26 '<doc xmlns="http://a.example.com" xmlns:b="http://b.example.com">' + 27 '<item id="1" color="red"/>' + 28 '<a:item id="2" xmlns:a="http://a.example.com" a:color="orange"/>' + 29 '<b:item id="3" color="yellow" />' + 30 '<item id="4" xmlns="http://a.example.com" color="green"/>' + 31 '<chapter id="c1" xmlns="http://b.example.com">' + 32 '<item id="5" color="blue" />' + 33 '<b:item id="6" b:color="indigo"/>' + 34 '</chapter>' + 35 '<chapter id="c2" xmlns="http://b.example.com" xmlns:b="http://a.example.com">' + 36 '<item id="7" b:color="violet"/>' + 37 '<b:item id="8" a:color="brown" xmlns:a="http://b.example.com"/>' + 38 '</chapter>' + 39 '</doc>', 40 'application/xml'); 41 42 var XROOT = docns.firstChild; 43 var XI1 = XROOT.firstChild; 44 var XI2 = XI1.nextSibling; 45 var XI3 = XI2.nextSibling; 46 var XI4 = XI3.nextSibling; 47 var XC1 = XI4.nextSibling; 48 var XI5 = XC1.firstChild; 49 var XI6 = XI5.nextSibling; 50 var XC2 = XC1.nextSibling; 51 var XI7 = XC2.firstChild; 52 var XI8 = XI7.nextSibling; 53 54 function nsResolver(prefix) 55 { 56 if (prefix == "b") 57 return "http://b.example.com"; 58 if (prefix == "a") 59 return "http://a.example.com"; 60 return null; 61 } 62 63 // Some of these tests originally used a default namespace, which is not available in JavaScript XPathEvaluator. 64 test(doc, doc, '/descendant::item', [DI1, DI2]); 65 test(docns, docns, '/descendant::a:item', [XI1, XI2, XI4, XI8], nsResolver); 66 test(docns, docns, '/descendant::b:*', [XI3, XC1, XI5, XI6, XC2, XI7], nsResolver); 67 shouldThrow('docns.evaluate("//x:*", docns, nsResolver, XPathResult.ANY_TYPE, null)'); 68 test(doc, doc, 'doc/child::*', [DI1, DC1]); 69 test(docns, docns, 'a:doc/child::*', [XI1, XI2, XI3, XI4, XC1, XC2], nsResolver); 70 test(doc, doc, '//attribute::color', [DI1.getAttributeNode("color"), DI2.getAttributeNode("color")]); 71 test(docns, docns, '//attribute::color', [XI1.getAttributeNode("color"), XI3.getAttributeNode("color"), XI4.getAttributeNode("color"), XI5.getAttributeNode("color")], nsResolver); 72 test(docns, docns, '//attribute::b:*', [XI6.getAttributeNodeNS("http://b.example.com", "color"), XI8.getAttributeNodeNS("http://b.example.com", "color")], nsResolver); 73 test(doc, doc, '//attribute::*', [DI1.getAttributeNode("id"), DI1.getAttributeNode("color"), DC1.getAttributeNode("id"), DI2.getAttributeNode("id"), DI2.getAttributeNode("color")]); 74 test(docns, docns, 'count(//attribute::*)', 18, nsResolver); 75 76 77 var doc = (new DOMParser).parseFromString( 78 '<doc><element />text<?one pi?><?two pi?><!--comment--></doc>', 79 'application/xml'); 80 81 var ROOT = doc.documentElement; 82 var TEXT = ROOT.firstChild.nextSibling; 83 var COMMENT = ROOT.lastChild; 84 var PI1 = TEXT.nextSibling; 85 var PI2 = PI1.nextSibling; 86 87 test(doc, doc, 'doc/child::text()', [TEXT]); 88 test(doc, doc, 'doc/child::comment()', [COMMENT]); 89 test(doc, doc, 'doc/child::processing-instruction()', [PI1, PI2]); 90 test(doc, doc, 'doc/child::processing-instruction("one")', [PI1]); 91 92 93 var successfullyParsed = true; 94 95 </script> 96 <script src="../../js/resources/js-test-post.js"></script> 97 </body> 98 </html> 99