abbreviations.html revision 5f90462bbf4efb0ac7bb65a852d5559d0ab30f0b
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> 11var doc = (new DOMParser).parseFromString( 12 '<doc>' + 13 ' <para id="1" />' + 14 ' <div id="2" />' + 15 ' <para id="3" />' + 16 '</doc>', 17 'application/xml'); 18test(doc, doc.documentElement, "para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]); 19test(doc, doc.documentElement, "*", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("div")[0], doc.getElementsByTagName("para")[1]]); 20 21doc = (new DOMParser).parseFromString('<doc>This is <i>some</i> text.</doc>', 'application/xml'); 22test(doc, doc.documentElement, "text()", [doc.documentElement.firstChild, doc.documentElement.lastChild]); 23 24doc = (new DOMParser).parseFromString('<doc name="foo" value="bar" />', 'application/xml'); 25test(doc, doc.documentElement, "@name", [doc.documentElement.getAttributeNode("name")]); 26test(doc, doc.documentElement, "@*", [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]); 27 28doc = (new DOMParser).parseFromString('<doc><para id="1" /><para id="2" /><para id="3" /></doc>', 'application/xml'); 29test(doc, doc.documentElement, "para[1]", [doc.getElementsByTagName("para")[0]]); 30test(doc, doc.documentElement, "para[last()]", [doc.getElementsByTagName("para")[2]]); 31 32doc = (new DOMParser).parseFromString( 33 '<doc>' + 34 ' <chapter><para id="1" /><para id="2" /></chapter>' + 35 ' <section><para id="3" /><sub><para id="4" /></sub></section>' + 36 ' <para id="4" />' + 37 '</doc>', 38 'application/xml'); 39test(doc, doc.documentElement, "*/para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]); 40 41doc = (new DOMParser).parseFromString( 42 '<doc>' + 43 ' <chapter id="1" /><chapter id="2" /><chapter id="3" />' + 44 ' <chapter id="4">' + 45 ' <section id="4.1" /><section id="4.2" /><section id="4.3" />' + 46 ' </chapter>' + 47 ' <chapter id="5">' + 48 ' <section id="5.1" /><section id="5.2" /><section id="5.3" />' + 49 ' </chapter>' + 50 '</doc>', 51 'application/xml'); 52test(doc, doc.documentElement, "/doc/chapter[5]/section[2]", [doc.getElementsByTagName("section")[4]]); 53 54doc = (new DOMParser).parseFromString( 55 '<doc>' + 56 ' <chapter><para id="1" /><para id="2" /></chapter>' + 57 ' <chapter><section><para id="3" /></section></chapter>' + 58 ' <para id="4" />' + 59 '</doc>', 60 'application/xml'); 61test(doc, doc.documentElement, "chapter//para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]); 62 63doc = (new DOMParser).parseFromString( 64 '<para id="0">' + 65 ' <div id="1" />' + 66 ' <para id="2">' + 67 ' <para id="3" />' + 68 ' </para>' + 69 '</para>', 70 'application/xml'); 71test(doc, '//para[@id="2"]', '//para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]); 72 73doc = (new DOMParser).parseFromString( 74 '<doc>' + 75 ' <item id="1">' + 76 ' <context />' + 77 ' <olist><item id="2" /></olist>' + 78 ' </item>' + 79 ' <olist><item id="3" /></olist>' + 80 '</doc>', 81 'application/xml'); 82test(doc, '//context', '//olist/item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]); 83 84doc = (new DOMParser).parseFromString( 85 '<doc id="0">' + 86 ' <para id="1"/>' + 87 '</doc>', 88 'application/xml'); 89test(doc, doc.documentElement, '.', [doc.documentElement]); 90 91doc = (new DOMParser).parseFromString( 92 '<para id="0">' + 93 ' <div id="1" />' + 94 ' <para id="2">' + 95 ' <para id="3" />' + 96 ' </para>' + 97 '</para>', 98 'application/xml'); 99test(doc, '//para[@id="2"]', '/para', [doc.getElementsByTagName("para")[2]]); 100 101doc = (new DOMParser).parseFromString( 102 '<doc id="0">' + 103 ' <chapter id="1">' + 104 ' <item id="2" />' + 105 ' <item id="3"><subitem id="4" /></item>' + 106 ' </chapter>' + 107 '</doc>', 108 'application/xml'); 109test(doc, '//item[@id="3"]', '..', [doc.getElementsByTagName("chapter")[0]]); 110 111doc = (new DOMParser).parseFromString( 112 '<doc id="0">' + 113 ' <chapter id="1" lang="en">' + 114 ' <item id="2" />' + 115 ' <item id="3"><subitem id="4" /></item>' + 116 ' </chapter>' + 117 '</doc>', 118 'application/xml'); 119test(doc, '//item[@id="3"]', '../@lang', [doc.getElementsByTagName("chapter")[0].getAttributeNode("lang")]); 120 121doc = (new DOMParser).parseFromString( 122 '<doc>' + 123 ' <para id="1" type="info" />' + 124 ' <para id="2" type="warning" />' + 125 ' <para id="3" type="warning" />' + 126 ' <para id="4" type="error" />' + 127 '</doc>', 128 'application/xml'); 129test(doc, doc.documentElement, 'para[@type="warning"]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]); 130 131doc = (new DOMParser).parseFromString( 132 '<doc>' + 133 ' <para id="1" type="info" />' + 134 ' <para id="2" type="warning" />' + 135 ' <para id="3" type="warning" />' + 136 ' <para id="4" type="warning" />' + 137 ' <para id="5" type="error" />' + 138 ' <para id="6" type="warning" />' + 139 ' <para id="7" type="warning" />' + 140 '</doc>', 141 'application/xml'); 142test(doc, doc.documentElement, 'para[@type="warning"][5]', [doc.getElementsByTagName("para")[6]]); 143test(doc, doc.documentElement, 'para[5][@type="warning"]', []); 144 145doc = (new DOMParser).parseFromString( 146 '<doc>' + 147 ' <chapter id="1" />' + 148 ' <chapter id="2"><title>Introduction</title></chapter>' + 149 ' <chapter id="3"><title>Body</title></chapter>' + 150 ' <chapter id="4">' + 151 ' <title>Another</title>' + 152 ' <title>Introduction</title>' + 153 ' </chapter>' + 154 '</doc>', 155 'application/xml'); 156test(doc, doc.documentElement, "chapter[title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]); 157 158doc = (new DOMParser).parseFromString( 159 '<doc>' + 160 ' <chapter id="1" />' + 161 ' <chapter id="2"><title /></chapter>' + 162 ' <chapter id="3"><title /><title /></chapter>' + 163 '</doc>', 164 'application/xml'); 165test(doc, doc.documentElement, "chapter[title]", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[2]]); 166 167doc = (new DOMParser).parseFromString( 168 '<doc>' + 169 ' <employee name="Alice" />' + 170 ' <employee name="Bob" secretary="Cathy" />' + 171 ' <employee name="Dianne" secretary="Edward" assistant="Fran" />' + 172 '</doc>', 173 'application/xml'); 174test(doc, doc.documentElement, "employee[@secretary and @assistant]", [doc.getElementsByTagName("employee")[2]]); 175 176 177var successfullyParsed = true; 178 179</script> 180<script src="/js/resources/js-test-post.js"></script> 181</body> 182</html> 183