4 testRunner
.dumpAsText();
6 src
= '<doc><elem>a<![CDATA[b]]>c</elem></doc>';
7 doc
= (new DOMParser
).parseFromString(src
, "application/xml");
9 elem
= doc
.documentElement
.firstChild
;
10 aText
= elem
.firstChild
;
11 bText
= elem
.firstChild
.nextSibling
;
12 cText
= elem
.lastChild
;
14 function test(expr
, context
) {
15 nodeset
= doc
.evaluate(expr
, context
, null, XPathResult
.ORDERED_NODE_ITERATOR_TYPE
, null);
17 while (currNode
= nodeset
.iterateNext()) {
20 str
+= currNode
.nodeValue
;
23 document
.write(expr
+ ", " + (context
.nodeValue
? context
.nodeValue
: context
) + ": \"" + str
+ "\"<br>");
26 document
.write("<xmp>" + src
+ "</xmp>");
28 test("child::*", elem
);
29 test("child::node()", elem
);
30 test("descendant::*", elem
);
31 test("descendant::node()", elem
);
32 test("descendant::node()[2]", elem
);
33 test("ancestor-or-self::node()", bText
);
34 test("ancestor-or-self::*", bText
);
35 test("ancestor-or-self::node()", aText
);
36 test("ancestor-or-self::*", aText
);
37 test("following::node()", elem
);
38 test("following::node()", aText
);
39 test("following::text()", aText
);
40 test("following::node()", bText
);
41 test("following-sibling::node()", elem
);
42 test("following-sibling::node()", aText
);
43 test("following-sibling::text()", aText
);
44 test("following-sibling::node()", bText
);
45 test("preceding::node()", bText
);
46 test("preceding-sibling::node()", bText
);
47 test("preceding::node()", cText
);
48 test("preceding::text()", cText
);
49 test("preceding-sibling::node()", cText
);
50 test("preceding-sibling::text()", cText
);
51 test("self::node()", bText
);