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>


ExpressionResultExpected (compiled)

Results

@val 123 123//x/text() sub text sub text//*/comment() -122.0 -122.0 count(//*/comment()) 2 2sum(//@*) 123 123sum(//*/comment()) 378 378true() true truenot(false()) true truecount(//*[position()=2]) 2 2name(/*/*/*[position()=2]) c cname(/*/*/*[last()]) d dcount(//c/following::*) 2 2count(/a/b/b/following::*) 3 3count(//d/preceding::*) 2 2name(//attribute::*) val valcount(//b/child::*) 3 3count(//x/ancestor-or-self::*) 2 2count(//b/descendant-or-self::*) 4 4count(//self::*) 6 6count(/a/descendant::*) 5 5count(/a/descendant::x) 1 1count(/a/descendant::b) 2 2count(/a/descendant::b[@val=123]) 1 1count(//c/ancestor::a) 1 1name(//d/parent::*) b bcount(//c/ancestor::*) 2 2name(/a/b/ancestor::*) a aname(/a/b/c/following-sibling::*) d dcount(//b/following-sibling::*) 3 3count(//b|//a) 3 3count(//d/preceding-sibling::*) 2 2-3 * 4 -12 -12-3.1 * 4 -12.4 -12.412 div 5 2.4 2.43 * 7 21 21-5.5 >= -5.5 true true-5.5 < 3 true true-6.0 < -7 false false12 < 14 true true12 > 14 false false14 <= 14 true true/a or /b true true/c or /b false false/a and /b false false/a and /*/b true true18-12 6 618+12 30 30count(//a|//b) 3 3count(//*[@val]) 1 1name(//*[@val=123]) b b3=4 false false3!=4 true true12=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 123count(//*/b) 2 2name(/*/*/*[2]) c cname(/*) a aname(/a) a aname(/a/b) b bname(/*/*) b bname(/a/b/c) c ccount(/a/b/*) 3 3ceiling(3.5) 4 4concat('first ','second',' third','') first second third first second thirdceiling(5) 5 5floor(3.5) 3 3floor(5) 5 5string-length('try') 3 3concat(name(/a/b[1]/*[1]),' ',name(/a/b/*[2])) b c b ccount(/a/b/*) 3 3count(//*) 6 6count(//b) 2 2contains('base','as') true truecontains('base','x') false falsenot(contains('base','as')) false falsestarts-with('blabla','bla') true truestarts-with('blebla','bla') false falsesubstring('12345',2,3) 234 234substring('12345',2) 2345 2345substring('12345',2,6) 2345 2345concat('[',normalize-space(' before and after '),']') [before and after] [before and after]//* 6 62+3+4+5 14 1420-2-3+5 20 20count(/a/x[1]) 1 1name(/a/*[2]) x xname(/a/*[1]) b bname(/a/x[1]) x xcount(/a/b/c[1]) 1 1count(/a/b/c[position()=1]) 1 1count(/a/b/d[position()=3]) 0 0//*[@val]/@val 123 123//x[text()='sub text']/@target xyz xyzsubstring('123.4',1) 123.4 123.4//** syntax error syntax 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

 

转载于:https://www.cnblogs.com/yangyh/archive/2010/07/08/1773334.html

tinyxpath 解析简单 的小工具,输出是一个静态库。可 找到xml文档. TinyXml介绍 TinyXml是一个基于DOM模型的、非验证的轻量级C++解释器 一. XML解析模型: 目前XML的解析主要有两大模型:SAX和DOM。 SAX是基于事件的,其基本工作流程是分析XML文档,当发现了一个新的元素时,产生一个对应事件,并调用相应的用户处理函数。这种方式占用内存少,速度快,但用户程序相应得会比较复杂。 DOM(文档对象模型),则是在分析时,一次性的将整个XML文档进行分析,并在内存中形成对应的树结构,同时,向用户提供一系列的接口来访问和编辑该树结构。这种方式占用内存大,速度往往慢于SAX,但可以给用户提供一个面向对象的访问接口,对用户更为友好。 另据说,一些同时提供了SAX和DOM接口的库,是在底层先实现SAX,再在SAX的基础上实现DOM 对于一个特定的XML文档而言,其正确性分为两个层次。 首先是其格式应该符合XML的基本格式要求,比如第一行要有声明,标签的嵌套层次必须前后一致等等,符合这些要求的文件,就是一个合格的XML文件,称作well-formatted。 其次,一个XML文档因其内容的不同还必须在语义上符合相应的标准,这些标准由相应的DTD文件或者Schema文件来定义,符合了这些定义要求的XML文件,称作valid。 因此,解析器也分为两种,一种是验证的,即会跟据XML文件中的声明,用相应的DTD文件对XML文件进行校验,检查它是否满足DTD文件的要求。另一种是忽略DTD文件,只要基本格式正确,就可以进行解析。 就我所知,验证的解析器通常都是比较重量级的。TinyXml不支持验证,但是体积很小,用在解析格式较为简单的XML文件,比如配置文件时,特别的合适。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值