XPath表达式

昨天需要统计一个xml文件中有多少个节点。用到了XPath表达式。

我用的功能很简单,就是把所有的这个节点的内容全部取出来。

//Element[not(@Attr1) and @Attr2]

这句的意思是:选择Element,该Element包含Attr2, 不包含Attr1

//Element[not(@Attr1) and @Attr2 and contains(@Attr2, 'http')]

这句的意思是:选择Element,该Element包含Attr2, 不包含Attr1, 而且Attr2属性中包含'http'字段。

有空再慢慢添加XPath的其他功能。

2011-3-10

/*/Summary[@Type='Overall']

/*/表示根,这个表达式查找,根下type = Overall 的Summary

2011-4-7

//Line[contains(.,'149') and ../Function='GetData']

表示寻找包含149的Line,并且该Line的同级的Function 名是'GetData'

Space:Statement/Space:lineno[contains(../Space:result,'NOT') or contains(../Space:result,'PARTIALLY')]

这个是带命名空间的,寻找Statement下的lineno, 该lineno的同级的result元素中包含'NOT' 或'PARTIALLY'

原文地址:https://www.cnblogs.com/mantian/p/1855712.html