随笔-341  评论-2670  文章-0  trackbacks-0
    为了整理出可以实现的XPath,我把根DTD相关的两个内置函数去掉了,Microsoft扩展的11个函数也没有考虑进去。XPath是一门非图灵完备的、没有副作用的、弱类型以及很难看的语言,用于把一个XML的某个节点转换成一些节点。

Context:上下文。指的是使用指定条件正在搜索的XML路径的节点。

ContextList:被PREDICATE过滤的列表

 

UNIT

Name                                                          :节点的名字必须是Name

Namespace:*                                            :节点的namespace必须是Namespace

*                                                                   :任何节点

@Name                                                      :节点必须是属性而且名字必须是Name

@*                                                               :任何属性

comment()                                                 :注释节点

node()                                                         :任何节点

text()                                                           :文字节点

processing-instruction(Name?)           processing-instruction节点,名字必须是Name(可选)

 

PREDICATE

  XPATH                                                          ContextXPATH非空

  VALUE(<|>|=|<=|>=|!=)VALUE            :比较操作符

  VALUE                                                          :位置是VALUE,从1开始

  PREDICATE(and|or)PREDICATE            :逻辑操作符

  not(PREDICATE)                                        :逻辑操作符

 

VALUE

  常数

  VALUE(+|-|*|div|mod)VALUE               :操作符

  (VALUE)                                                       VALUE

  count(XPATH)                                            :数目

  last()                                                            ContextList的数目

  local-name(XPATH?)                                :返回没有namespace的名字,没参数则为ContextList

  name(XPATH?)                                          :返回全名,没参数则为ContextList

  position()                                                    ContextContextList中的位置

  concat(Str1,Str2[,Str3…])                       :连接字符串

  contains(Big,Small)                                  :返回Big中是否出现Small

  normalize-space(String)                         :将String头尾的空白去掉,中间的连续空白使用一个空格代替

  starts-with(Big,Small)                             :返回Big是否由Small开头

  string(Object)                                            :类型转换,如果ObjectNodeList则将NodeList变为NodeList[1],然后讲NodeList所有子节点的值连接起来

  string-length(String)                                :长度

  substring(String,Start,Length)              :子串

  substring-after(Big,Small)                      :返回Big中位于Small后的部分

  substring-before(Big,Small)                            :返回Big中位于Small之前的部分

  translate(A,B,C)                                       :将A中的所有B[i]换成C[i]B[position()>length(C)]换为空字符串

  boolean(X)                                                  :类型转换,非0true,非空true

  false()                                                          :返回false

  true()                                                           :返回true

  ceiling,floor,round(X)                               :转换浮点

  sum(XPATH)                                                :所有值相加

  number(X)                                                  :类型转换,1true0false,其他类型转string后转number

 

XPATH

  .                                                                     Context

  ..                                                                   Context的父节点

  /                                                                    :根节点

  /UNIT                                                          :根节点中满足UNIT的子节点,UNITContext为根节点

  XPATH /UNIT                                             XPATH中满足UNIT的子节点,UNITContextNODELIST的其中一项

  //UNIT                                                         :根节点中满足UNIT的直接或间接子节点,UNITContext为根节点

  XPATH //UNIT                                            XPATH中满足UNIT的直接或间接子节点,UNITContextXPath的其中一项

  (XPATH)                                                        XPATH

  XPATH [PREDICATE]                                 :筛选

  Axis::XPATH

ancestor                                                 XPATH的直接或间接祖先

ancestor-or-self                                    ancestorXPath

attribute                                                 XPATH的所有属性

child                                                         XPATH的所有子节点(包括属性)

descendant                                            XPATH的直接或间接子节点

descendant-or-self                              descendantXPATH

following                                                 :所有完全处于XPATH后的节点

following-sibling                                   following中与自己处于同一层次的节点

preceding                                                        :所有完全处于XPATH之前的节点

preceding-sibling                                  preceding中与自己处于同一层次的节点

self                                                           XPATH

parent                                                     XPATH的父节点

  XPATH|XPATH                                            :并集

 

优先级:

  ()  >  ::  >  []  >  /,//  >  |

posted on 2008-06-20 01:44 陈梓瀚(vczh) 阅读(4835) 评论(1)  编辑 收藏 引用 所属分类: C++

评论:
# re: 标准XPath语法整理 2008-06-22 07:03 | 影视剧
XPath真的很好用的  回复  更多评论
  

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理