TinyXPath examples / regression tests

Input XML tree

<a>
   <b val='123'>
      <b />
      <c />
<!-- -122.0 -->
      <d />
   </b>
<!-- 500.0 -->
   <x target='xyz'>
sub text    </x>
</a>


Results

ExpressionResultExpected (compiled)
@val123123
//x/text()sub textsub text
//*/comment() -122.0 -122.0
count(//*/comment())22
sum(//@*)123123
sum(//*/comment())378378
true()truetrue
not(false())truetrue
count(//*[position()=2])22
name(/*/*/*[position()=2])cc
name(/*/*/*[last()])dd
count(//c/following::*)22
count(/a/b/b/following::*)33
count(//d/preceding::*)22
name(//attribute::*)valval
count(//b/child::*)33
count(//x/ancestor-or-self::*)22
count(//b/descendant-or-self::*)44
count(//self::*)66
count(/a/descendant::*)55
count(/a/descendant::x)11
count(/a/descendant::b)22
count(/a/descendant::b[@val=123])11
count(//c/ancestor::a)11
name(//d/parent::*)bb
count(//c/ancestor::*)22
name(/a/b/ancestor::*)aa
name(/a/b/c/following-sibling::*)dd
count(//b/following-sibling::*)33
count(//b|//a)33
count(//d/preceding-sibling::*)22
-3 * 4-12-12
-3.1 * 4-12.4-12.4
12 div 52.42.4
3 * 72121
-5.5 >= -5.5truetrue
-5.5 < 3truetrue
-6.0 < -7falsefalse
12 < 14truetrue
12 > 14falsefalse
14 <= 14truetrue
/a or /btruetrue
/c or /bfalsefalse
/a and /bfalsefalse
/a and /*/btruetrue
18-1266
18+123030
count(//a|//b)33
count(//*[@val])11
name(//*[@val=123])bb
3=4falsefalse
3!=4truetrue
12=12truetrue
'here is a string'='here is a string'truetrue
'here is a string'!='here is a string'falsefalse
/a/b/@val123123
count(//*/b)22
name(/*/*/*[2])cc
name(/*)aa
name(/a)aa
name(/a/b)bb
name(/*/*)bb
name(/a/b/c)cc
count(/a/b/*)33
ceiling(3.5)44
concat('first ','second',' third','')first second thirdfirst second third
ceiling(5)55
floor(3.5)33
floor(5)55
string-length('try')33
concat(name(/a/b[1]/*[1]),' ',name(/a/b/*[2]))b cb c
count(/a/b/*)33
count(//*)66
count(//b)22
contains('base','as')truetrue
contains('base','x')falsefalse
not(contains('base','as'))falsefalse
starts-with('blabla','bla')truetrue
starts-with('blebla','bla')falsefalse
substring('12345',2,3)234234
substring('12345',2)23452345
substring('12345',2,6)23452345
concat('[',normalize-space(' before and after '),']')[before and after][before and after]
//*66
2+3+4+51414
20-2-3+52020
count(/a/x[1])11
name(/a/*[2])xx
name(/a/*[1])bb
name(/a/x[1])xx
count(/a/b/c[1])11
count(/a/b/c[position()=1])11
count(/a/b/d[position()=3])00
//*[@val]/@val123123
//x[text()='sub text']/@targetxyzxyz
substring('123.4',1)123.4123.4
//**syntax errorsyntax error

Input XML tree

<xml>
   <text>
within    </text>
</xml>


ExpressionResultExpected (compiled)
/xml/text/text()withinwithin

RSS feed examples

These examples show how to decode a typical XML file : the TinyXPath RSS feed

RSS version (XPath expr : /rss/@version) : 2.0
Nb of news messages (XPath expr : count(/rss/channel/item)) : 7

Xpath exprvalue
concat(/rss/channel/item[1]/pubDate/text(),' : ',/rss/channel/item[1]/title/text())Sun, 18 Jan 2004 13:33:55 GMT : TinyXPath 1.2.1 is released
concat(/rss/channel/item[2]/pubDate/text(),' : ',/rss/channel/item[2]/title/text())Fri, 09 Jan 2004 21:24:09 GMT : TinyXPath 1.2 is released
concat(/rss/channel/item[3]/pubDate/text(),' : ',/rss/channel/item[3]/title/text())Wed, 07 Jan 2004 08:52:10 GMT : Version 1.1 is out
concat(/rss/channel/item[4]/pubDate/text(),' : ',/rss/channel/item[4]/title/text())Tue, 11 Jun 2002 19:31:51 GMT : Release 0.3 is out
concat(/rss/channel/item[5]/pubDate/text(),' : ',/rss/channel/item[5]/title/text())Mon, 27 May 2002 20:14:31 GMT : Release 0.2 is out
concat(/rss/channel/item[6]/pubDate/text(),' : ',/rss/channel/item[6]/title/text())Tue, 21 May 2002 21:23:53 GMT : First release 0.1 is out
concat(/rss/channel/item[7]/pubDate/text(),' : ',/rss/channel/item[7]/title/text())Tue, 14 May 2002 20:09:56 GMT : Syntax decoding is done