Home | History | Annotate | Download | only in 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 function 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 
     21 doc = (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 
     27 shouldBe('doc.evaluate("//@attr1", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1');
     28 shouldBe('doc.evaluate("//@attr2", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0');
     29 shouldBe('doc.evaluate("//@ns:attr2", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1');
     30 shouldBe('doc.evaluate("//@ns:xmlns", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1');
     31 shouldThrow('doc.evaluate("//@xml:id", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength');
     32 shouldBe('doc.evaluate("//@xml:id", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1');
     33 shouldBe('doc.evaluate("//@*", doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '4');
     34 shouldBe('doc.evaluate("//@ns:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '2');
     35 shouldBe('doc.evaluate("//@xml:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '1');
     36 shouldBe('doc.evaluate("//@xmlns", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0');
     37 shouldBe('doc.evaluate("//@xmlns:*", doc, nsResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength', '0');
     38 
     39 var successfullyParsed = true;
     40 
     41 </script>
     42 <script src="../js/resources/js-test-post.js"></script>
     43 </body>
     44 </html>
     45