Home | History | Annotate | Download | only in py-dom-xpath
      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         '<para id="1" />' +
     14         '<div id="2" />' +
     15         '<para id="3" />' +
     16    '</doc>',
     17     'application/xml');
     18 test(doc, doc.documentElement, 'child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
     19 test(doc, doc.documentElement, 'child::*', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
     20 
     21 var doc = (new DOMParser).parseFromString(
     22     '<doc>This is <i>some</i> text.</doc>',
     23     'application/xml');
     24 test(doc, doc.documentElement, 'child::text()', [doc.documentElement.firstChild, doc.documentElement.lastChild]);
     25 test(doc, doc.documentElement, 'child::node()', [doc.documentElement.firstChild, doc.documentElement.firstChild.nextSibling, doc.documentElement.lastChild]);
     26 
     27 var doc = (new DOMParser).parseFromString(
     28     '<doc name="foo" value="bar" />',
     29     'application/xml');
     30 test(doc, doc.documentElement, 'attribute::name', [doc.documentElement.getAttributeNode("name")]);
     31 test(doc, doc.documentElement, 'attribute::*', [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]);
     32 
     33 var doc = (new DOMParser).parseFromString(
     34     '<doc>' +
     35         '<para id="1">' +
     36             '<div id="2" />' +
     37             '<para id="3" />' +
     38         '</para>' +
     39    '</doc>',
     40     'application/xml');
     41 test(doc, doc.documentElement, 'descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
     42 
     43 var doc = (new DOMParser).parseFromString(
     44     '<doc>' +
     45         '<div id="1">' +
     46             '<div id="2">' +
     47                 '<context />' +
     48             '</div>' +
     49             '<div id="3" />' +
     50         '</div>' +
     51         '<div id="4" />' +
     52    '</doc>',
     53     'application/xml');
     54 test(doc, '//context', 'ancestor::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[1]]);
     55 
     56 var doc = (new DOMParser).parseFromString(
     57     '<doc>' +
     58         '<div id="1">' +
     59             '<div id="2" />' +
     60             '<div id="3" />' +
     61         '</div>' +
     62         '<div id="4" />' +
     63    '</doc>',
     64     'application/xml');
     65 test(doc, '//div[@id="3"]', 'ancestor-or-self::div', [doc.getElementsByTagName("div")[0], doc.getElementsByTagName("div")[2]]);
     66 
     67 var doc = (new DOMParser).parseFromString(
     68     '<para id="0">' +
     69         '<div id="1" />' +
     70         '<para id="2">' +
     71             '<para id="3" />' +
     72         '</para>' +
     73    '</para>',
     74     'application/xml');
     75 test(doc, doc.documentElement, 'descendant-or-self::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
     76 
     77 var doc = (new DOMParser).parseFromString(
     78     '<doc>' +
     79         '<para />' +
     80    '</doc>',
     81     'application/xml');
     82 test(doc, doc.documentElement, 'self::para', []);
     83 test(doc, 'para', 'self::para', [doc.documentElement.firstChild]);
     84 
     85 var doc = (new DOMParser).parseFromString(
     86     '<doc>' +
     87         '<chapter><para id="1" /><para id="2" /></chapter>' +
     88         '<chapter><section><para id="3" /></section></chapter>' +
     89         '<para id="4" />' +
     90    '</doc>',
     91     'application/xml');
     92 test(doc, doc.documentElement, 'child::chapter/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
     93 
     94 var doc = (new DOMParser).parseFromString(
     95     '<doc>' +
     96         '<chapter><para id="1" /><para id="2" /></chapter>' +
     97         '<section><para id="3" /><sub><para id="4" /></sub></section>' +
     98         '<para id="4" />' +
     99    '</doc>',
    100     'application/xml');
    101 test(doc, doc.documentElement, 'child::*/child::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
    102 
    103 var doc = (new DOMParser).parseFromString(
    104     '<doc><a><b><context /></b></a></doc>',
    105     'application/xml');
    106 test(doc, '//context', '/', [doc]);
    107 
    108 var doc = (new DOMParser).parseFromString(
    109     '<doc>' +
    110         '<para id="1"><context /></para>' +
    111         '<para id="2" />' +
    112    '</doc>',
    113     'application/xml');
    114 test(doc, '//context', '/descendant::para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
    115 
    116 var doc = (new DOMParser).parseFromString(
    117     '<doc>' +
    118         '<item id="1">' +
    119             '<context />' +
    120             '<olist><item id="2" /></olist>' +
    121         '</item>' +
    122         '<olist><item id="3" /></olist>' +
    123    '</doc>',
    124     'application/xml');
    125 test(doc, '//context', '/descendant::olist/child::item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]);
    126 
    127 var doc = (new DOMParser).parseFromString(
    128     '<doc>' +
    129         '<div id="1" />' +
    130         '<para id="2" />' +
    131         '<para id="3" />' +
    132    '</doc>',
    133     'application/xml');
    134 test(doc, doc.documentElement, 'child::para[position()=1]', [doc.getElementsByTagName("para")[0]]);
    135 
    136 var doc = (new DOMParser).parseFromString(
    137     '<doc>' +
    138         '<para id="1" />' +
    139         '<para id="2" />' +
    140         '<div id="3" />' +
    141    '</doc>',
    142     'application/xml');
    143 test(doc, doc.documentElement, 'child::para[position()=last()]', [doc.getElementsByTagName("para")[1]]);
    144 
    145 var doc = (new DOMParser).parseFromString(
    146     '<doc>' +
    147         '<para id="1" />' +
    148         '<para id="2" />' +
    149         '<para id="3" />' +
    150         '<div id="4" />' +
    151    '</doc>',
    152     'application/xml');
    153 test(doc, doc.documentElement, 'child::para[position()=last()-1]', [doc.getElementsByTagName("para")[1]]);
    154 
    155 var doc = (new DOMParser).parseFromString(
    156     '<doc>' +
    157         '<div id="1" /><para id="2" />' +
    158         '<div id="3" /><para id="4" />' +
    159         '<div id="5" /><para id="6" />' +
    160    '</doc>',
    161     'application/xml');
    162 test(doc, doc.documentElement, 'child::para[position()>1]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
    163 
    164 var doc = (new DOMParser).parseFromString(
    165     '<doc>' +
    166         '<chapter id="1" /><chapter id="2" />' +
    167         '<context />' +
    168         '<chapter id="3" /><chapter id="4" />' +
    169    '</doc>',
    170     'application/xml');
    171 test(doc, '//context', 'following-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[2]]);
    172 test(doc, '//context', 'preceding-sibling::chapter[position()=1]', [doc.getElementsByTagName("chapter")[1]]);
    173 
    174 var xml = "<doc>"
    175 for (i = 1; i <= 10; ++i) {
    176     for (j = 1; j <= 10; ++j)
    177         xml += '<figure id="' + ((i*10)+j) + '%d">';
    178     for (j = 1; j <= 10; ++j)
    179         xml += '';
    180 }
    181 xml += "</doc>"
    182 var doc = (new DOMParser).parseFromString(xml, 'application/xml');
    183 test(doc, doc.documentElement, '/descendant::figure[position()=42]', [doc.getElementsByTagName("figure")[41]]);
    184 
    185 var doc = (new DOMParser).parseFromString(
    186     '' +
    187         '' +
    188         '' +
    189           '
' + 190 '' + 191 '' + 192 '
' + 193 '' + 194 '', 195 'application/xml'); 196 test(doc, doc.documentElement, '/child::doc/child::chapter[position()=5]/child::section[position()=2]', [doc.getElementsByTagName("section")[4]]); 197 198 var doc = (new DOMParser).parseFromString( 199 '' + 200 '' + 201 '' + 202 '' + 203 '' + 204 '' + 205 '' + 206 '' + 207 '', 208 'application/xml'); 209 test(doc, doc.documentElement, 'child::para[attribute::type="warning"][position()=5]', [doc.getElementsByTagName("para")[6]]); 210 test(doc, doc.documentElement, 'child::para[position()=5][attribute::type="warning"]', []); 211 212 var doc = (new DOMParser).parseFromString( 213 '' + 214 '' + 215 'Introduction' + 216 'Body' + 217 '' + 218 'Another' + 219 'Introduction' + 220 '' + 221 '', 222 'application/xml'); 223 test(doc, doc.documentElement, "child::chapter[child::title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]); 224 225 var doc = (new DOMParser).parseFromString( 226 '' + 227 '' + 228 '</chapter>'</span> + <a class="l" name="229"> 229 </a> <span class="s">'<chapter id="3"><title /><title /></chapter>'</span> + <a class="hl" name="230"> 230 </a> <span class="s">'</doc>'</span>, <a class="l" name="231"> 231 </a> <span class="s">'<a href="/android-4.1.1_r1.0/s?path=application">application</a>/<a href="/android-4.1.1_r1.0/s?path=application/xml">xml</a>'</span>); <a class="l" name="232"> 232 </a><span class="n">test</span>(<span class="n">doc</span>, <a href="/android-4.1.1_r1.0/s?path=doc.documentElement">doc.documentElement</a>, <span class="s">"child::chapter[child::title]"</span>, [<a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"chapter"</span>)[<span class="n">1</span>], <a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"chapter"</span>)[<span class="n">2</span>]]); <a class="l" name="233"> 233 </a> <a class="l" name="234"> 234 </a><span class="n">var</span> <b>doc =</b> (<span class="n">new</span> <span class="n">DOMParser</span>).<span class="n">parseFromString</span>( <a class="l" name="235"> 235 </a> <span class="s">'<doc>'</span> + <a class="l" name="236"> 236 </a> <span class="s">'<chapter id="1" />'</span> + <a class="l" name="237"> 237 </a> <span class="s">'<appendix id="2" />'</span> + <a class="l" name="238"> 238 </a> <span class="s">'<para id="3" />'</span> + <a class="l" name="239"> 239 </a> <span class="s">'<chapter id="4" />'</span> + <a class="hl" name="240"> 240 </a> <span class="s">'</doc>'</span>, <a class="l" name="241"> 241 </a> <span class="s">'<a href="/android-4.1.1_r1.0/s?path=application">application</a>/<a href="/android-4.1.1_r1.0/s?path=application/xml">xml</a>'</span>); <a class="l" name="242"> 242 </a><span class="n">test</span>(<span class="n">doc</span>, <a href="/android-4.1.1_r1.0/s?path=doc.documentElement">doc.documentElement</a>, <span class="s">"child::*[self::chapter or self::appendix]"</span>, [<a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"chapter"</span>)[<span class="n">0</span>], <a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"appendix"</span>)[<span class="n">0</span>], <a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"chapter"</span>)[<span class="n">1</span>]]); <a class="l" name="243"> 243 </a> <a class="l" name="244"> 244 </a><span class="n">var</span> <b>doc =</b> (<span class="n">new</span> <span class="n">DOMParser</span>).<span class="n">parseFromString</span>( <a class="l" name="245"> 245 </a> <span class="s">'<doc>'</span> + <a class="l" name="246"> 246 </a> <span class="s">'<chapter id="1" />'</span> + <a class="l" name="247"> 247 </a> <span class="s">'<appendix id="2" />'</span> + <a class="l" name="248"> 248 </a> <span class="s">'<para id="3" />'</span> + <a class="l" name="249"> 249 </a> <span class="s">'<chapter id="4" />'</span> + <a class="hl" name="250"> 250 </a> <span class="s">'<para id="5" />'</span> + <a class="l" name="251"> 251 </a> <span class="s">'</doc>'</span>, <a class="l" name="252"> 252 </a> <span class="s">'<a href="/android-4.1.1_r1.0/s?path=application">application</a>/<a href="/android-4.1.1_r1.0/s?path=application/xml">xml</a>'</span>); <a class="l" name="253"> 253 </a><span class="n">test</span>(<span class="n">doc</span>, <a href="/android-4.1.1_r1.0/s?path=doc.documentElement">doc.documentElement</a>, <span class="s">"child::*[self::chapter or self::appendix][position()=last()]"</span>, [<a href="/android-4.1.1_r1.0/s?path=doc.getElementsByTagName">doc.getElementsByTagName</a>(<span class="s">"chapter"</span>)[<span class="n">1</span>]]); <a class="l" name="254"> 254 </a> <a class="l" name="255"> 255 </a> <a class="l" name="256"> 256 </a><span class="n">var</span> <b>successfullyParsed =</b> <span class="n">true</span>; <a class="l" name="257"> 257 </a> <a class="l" name="258"> 258 </a></script> <a class="l" name="259"> 259 </a><<span class="n">script</span> <b>src=</b><span class="s">"<a href="/android-4.1.1_r1.0/s?path=">..</a>/<a href="/android-4.1.1_r1.0/s?path=">..</a>/<a href="/android-4.1.1_r1.0/s?path=js">js</a>/<a href="/android-4.1.1_r1.0/s?path=js/resources">resources</a>/<a href="/android-4.1.1_r1.0/s?path=js/resources/js-test-post.js">js-test-post.js</a>"</span>></<span class="n">script</span>> <a class="hl" name="260"> 260 </a></<span class="n">body</span>> <a class="l" name="261"> 261 </a></<span class="n">html</span>> <a class="l" name="262"> 262 </a></pre></div> <div id="Footer"> <p class="Center"> <a href="http://www.opensolaris.org/os/project/opengrok/"><img src="/android-4.1.1_r1.0/default/img/servedby.png" alt="Served by OpenGrok" title="Served by OpenGrok"/></a> </p> </div> </div> </body> </html>