zoukankan      html  css  js  c++  java
  • TINYXPATH (转)

    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

    Expression Result Expected (compiled)
    @val 123 123
    //x/text() sub text sub text
    //*/comment() -122.0 -122.0
    count(//*/comment()) 2 2
    sum(//@*) 123 123
    sum(//*/comment()) 378 378
    true() true true
    not(false()) true true
    count(//*[position()=2]) 2 2
    name(/*/*/*[position()=2]) c c
    name(/*/*/*[last()]) d d
    count(//c/following::*) 2 2
    count(/a/b/b/following::*) 3 3
    count(//d/preceding::*) 2 2
    name(//attribute::*) val val
    count(//b/child::*) 3 3
    count(//x/ancestor-or-self::*) 2 2
    count(//b/descendant-or-self::*) 4 4
    count(//self::*) 6 6
    count(/a/descendant::*) 5 5
    count(/a/descendant::x) 1 1
    count(/a/descendant::b) 2 2
    count(/a/descendant::b[@val=123]) 1 1
    count(//c/ancestor::a) 1 1
    name(//d/parent::*) b b
    count(//c/ancestor::*) 2 2
    name(/a/b/ancestor::*) a a
    name(/a/b/c/following-sibling::*) d d
    count(//b/following-sibling::*) 3 3
    count(//b|//a) 3 3
    count(//d/preceding-sibling::*) 2 2
    -3 * 4 -12 -12
    -3.1 * 4 -12.4 -12.4
    12 div 5 2.4 2.4
    3 * 7 21 21
    -5.5 >= -5.5 true true
    -5.5 < 3 true true
    -6.0 < -7 false false
    12 < 14 true true
    12 > 14 false false
    14 <= 14 true true
    /a or /b true true
    /c or /b false false
    /a and /b false false
    /a and /*/b true true
    18-12 6 6
    18+12 30 30
    count(//a|//b) 3 3
    count(//*[@val]) 1 1
    name(//*[@val=123]) b b
    3=4 false false
    3!=4 true true
    12=12 true true
    'here is a string'='here is a string' true true
    'here is a string'!='here is a string' false false
    /a/b/@val 123 123
    count(//*/b) 2 2
    name(/*/*/*[2]) c c
    name(/*) a a
    name(/a) a a
    name(/a/b) b b
    name(/*/*) b b
    name(/a/b/c) c c
    count(/a/b/*) 3 3
    ceiling(3.5) 4 4
    concat('first ','second',' third','') first second third first second third
    ceiling(5) 5 5
    floor(3.5) 3 3
    floor(5) 5 5
    string-length('try') 3 3
    concat(name(/a/b[1]/*[1]),' ',name(/a/b/*[2])) b c b c
    count(/a/b/*) 3 3
    count(//*) 6 6
    count(//b) 2 2
    contains('base','as') true true
    contains('base','x') false false
    not(contains('base','as')) false false
    starts-with('blabla','bla') true true
    starts-with('blebla','bla') false false
    substring('12345',2,3) 234 234
    substring('12345',2) 2345 2345
    substring('12345',2,6) 2345 2345
    concat('[',normalize-space(' before and after '),']') [before and after] [before and after]
    //* 6 6
    2+3+4+5 14 14
    20-2-3+5 20 20
    count(/a/x[1]) 1 1
    name(/a/*[2]) x x
    name(/a/*[1]) b b
    name(/a/x[1]) x x
    count(/a/b/c[1]) 1 1
    count(/a/b/c[position()=1]) 1 1
    count(/a/b/d[position()=3]) 0 0
    //*[@val]/@val 123 123
    //x[text()='sub text']/@target xyz xyz
    substring('123.4',1) 123.4 123.4
    //** syntax error syntax error

    Input XML tree

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


    Expression Result Expected (compiled)
    /xml/text/text() within within

    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 expr value
    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

     
  • 相关阅读:
    每周总结⑤
    每周总结④——所遇问题
    Leetcode566. 重塑矩阵
    移动应用开发三种方式
    html5离线存储manifest
    拓端tecdat|python中的copula:Frank、Clayton和Gumbel copula模型估计与可视化
    拓端tecdat|R语言用极大似然和梯度下降算法估计GARCH(p)过程
    拓端tecdat|R语言Keras用RNN、双向RNNs递归神经网络、LSTM分析预测温度时间序列、 IMDB电影评分情感
    JAVA中CountDownLatch的简单示例
    网络编程基础篇
  • 原文地址:https://www.cnblogs.com/yangyh/p/1773334.html
Copyright © 2011-2022 走看看