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, "para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1]]);
     19 test(doc, doc.documentElement, "*", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("div")[0], doc.getElementsByTagName("para")[1]]);
     20 
     21 doc = (new DOMParser).parseFromString('<doc>This is <i>some</i> text.</doc>', 'application/xml');
     22 test(doc, doc.documentElement, "text()", [doc.documentElement.firstChild, doc.documentElement.lastChild]);
     23 
     24 doc = (new DOMParser).parseFromString('<doc name="foo" value="bar" />', 'application/xml');
     25 test(doc, doc.documentElement, "@name", [doc.documentElement.getAttributeNode("name")]);
     26 test(doc, doc.documentElement, "@*", [doc.documentElement.getAttributeNode("name"), doc.documentElement.getAttributeNode("value")]);
     27 
     28 doc = (new DOMParser).parseFromString('<doc><para id="1" /><para id="2" /><para id="3" /></doc>', 'application/xml');
     29 test(doc, doc.documentElement, "para[1]", [doc.getElementsByTagName("para")[0]]);
     30 test(doc, doc.documentElement, "para[last()]", [doc.getElementsByTagName("para")[2]]);
     31 
     32 doc = (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');
     39 test(doc, doc.documentElement, "*/para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
     40 
     41 doc = (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');
     52 test(doc, doc.documentElement, "/doc/chapter[5]/section[2]", [doc.getElementsByTagName("section")[4]]);
     53 
     54 doc = (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');
     61 test(doc, doc.documentElement, "chapter//para", [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
     62 
     63 doc = (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');
     71 test(doc, '//para[@id="2"]', '//para', [doc.getElementsByTagName("para")[0], doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
     72 
     73 doc = (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');
     82 test(doc, '//context', '//olist/item', [doc.getElementsByTagName("item")[1], doc.getElementsByTagName("item")[2]]);
     83 
     84 doc = (new DOMParser).parseFromString(
     85     '<doc id="0">' +
     86     '    <para id="1"/>' +
     87     '</doc>',
     88     'application/xml');
     89 test(doc, doc.documentElement, '.', [doc.documentElement]);
     90 
     91 doc = (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');
     99 test(doc, '//para[@id="2"]', './para', [doc.getElementsByTagName("para")[2]]);
    100 
    101 doc = (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');
    109 test(doc, '//item[@id="3"]', '..', [doc.getElementsByTagName("chapter")[0]]);
    110 
    111 doc = (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');
    119 test(doc, '//item[@id="3"]', '../@lang', [doc.getElementsByTagName("chapter")[0].getAttributeNode("lang")]);
    120 
    121 doc = (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');
    129 test(doc, doc.documentElement, 'para[@type="warning"]', [doc.getElementsByTagName("para")[1], doc.getElementsByTagName("para")[2]]);
    130 
    131 doc = (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');
    142 test(doc, doc.documentElement, 'para[@type="warning"][5]', [doc.getElementsByTagName("para")[6]]);
    143 test(doc, doc.documentElement, 'para[5][@type="warning"]', []);
    144 
    145 doc = (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');
    156 test(doc, doc.documentElement, "chapter[title='Introduction']", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[3]]);
    157 
    158 doc = (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');
    165 test(doc, doc.documentElement, "chapter[title]", [doc.getElementsByTagName("chapter")[1], doc.getElementsByTagName("chapter")[2]]);
    166 
    167 doc = (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');
    174 test(doc, doc.documentElement, "employee[@secretary and @assistant]", [doc.getElementsByTagName("employee")[2]]);
    175 
    176 
    177 var successfullyParsed = true;
    178 
    179 </script>
    180 <script src="../../js/resources/js-test-post.js"></script>
    181 </body>
    182 </html>
    183