`
semi_sleep
  • 浏览: 99091 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

读XML in a Nutshell (6)

    博客分类:
  • XML
XML 
阅读更多

本篇关于Chapter 9 XPath。
跟其他的语言一样,xpath expression由变量和操作构成。在变量的类型上,有Boolean,String,Number跟xpath独有的Node Set,需要注意的是,xpath是弱类型的语言,它会自动做类型转换,唯一例外的是Node Set不能由另外三种类型转换得到。在操作方面,xpath的操作是基于context(照我的理解,context包括current node set还有current node)的,也就是说由context跟input来决定output。其中操作包括运算符(+ - * DIV MOD = > < != ...),方法,还有location path,所有的操作都有返回值(也就意味着没有所谓void的方法)。location path是xpath特有的操作方式,它以Node Set作为返回值,它由若干的"location step + /"组成,每个location step由axis(可被简化) + node test + predicate(可省略,predicate是一个Boolean值)组成。
以下是要点:

1.Xpath处理的是xml中的root node,element nodes,text nodes,attribute nodes,comment nodes,processing-instruction nodes,namespace nodes。而像CDATA,entity reference,dtd这种xpath是不管的。对于xpath来说root node指的不是document element,而是包括document element,顶层comment,processing-instruction等等的整个文档。同时,像xmlns,xmlns:prefix这种不被作为attribute看待,而是被认为是attribute nodes。

2.Location step中,/开始表示从root node开始,是绝对地址,其他的为相对地址。使用“//”选择context node以下的所有节点,同时包括context node,使用“..”选择父节点,使用“.”选择context node。

3.Node test中,采用xxx(prefix:xxx)选择某个名称的element,采用*选择所有的element,采用@xxx(@prefix:xxx)选择某个名称的attribute,采用@*选择所有的attribute,采用comment(),text(),procession-instruction()(可以用input参数来选择某个target的processing instruction)分别选择相应的node,采用node()选择所有的node。通过使用“|”号可以以或的关系把若干node test组合起来构成新的node test。

4.在axis方面,axis可以被省略,这种情况下默认是往子节点方向,如果不被省略,格式为axis::node test。Axis的类型包括ancestor,following-sibling,following,preceding,namespace,descendant,ancestor-or-self。

5.Predicate被“[”“]”这两个符号围住,其中的expression会在每个context node下evaluate一次,如果最终结果是true或者可以被转化成true,则context node将被包含在返回值中。

6.关于不同的类型间的转换机制,还有常用的funcion,可以去查相关的reference。

分享到:
评论

相关推荐

    XML.in.a.Nutshell

    XML.in.a.Nutshell(英文版)

    C# 5.0 in a Nutshell 5th

    C# 5.0 in a Nutshell 5th

    R in a Nutshell

    R in a Nutshell, pdf version

    Python in a Nutshell Third Edition 2017

    Python in a Nutshell 2017 最新版

    C# 6.0 in a Nutshell(6th) 无水印pdf

    C# 6.0 in a Nutshell(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系...

    C# 5.0 in a Nutshell, 5th Edition

    C# 5.0 in a Nutshell, 5th Edition 是英文的,别搞错了。

    Linux Kernel in a Nutshell

    Linux Kernel in a Nutshell Linux Kernel in a Nutshell

    Delphi in a Nutshell

    Delphi in a Nutshell is the first concise reference to Borland/Inprise Delphi available. It succinctly collects all the information you need in one easy-to-use, complete, and accurate volume that goes...

    USB in a Nutshell

    Starting out new with USB can be quite daunting. With the USB 2.0 specification at 650 pages one could easily be put off just by the sheer size of... None of these are detailed in the USB 2.0 Spec.

    Ruby In a Nutshell

    Ruby In a Nutshell

    Java in a Nutshell(中文版)

    Java in a Nutshell(6th) 英文无水印pdf 第6版 pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除

    C# 5.0 7.0 in a Nutshell EN

    C# 7.0 in a Nutshell EN,C# 5.0 in a Nutshell EN,英文原版PDF

    C# 6.0 in a Nutshell.pdf

    Dive in and discover why this Nutshell guide is considered the definitive reference on C#. Get up to speed with all aspects of the C# language, from the basics of syntax and variables, to advanced ...

    C# in a nutshell

    Get up to speed on C# language basics, including ...Learn .NET topics, including XML, collections, I/O and networking, memory management, reflection, attributes, security, and native interoperability

    C# 7.0 in A Nutshell

    Dive in and discover why this Nutshell guide is considered the definitive reference on C#. Get up to speed on the C# language, from the basics of syntax and variables to advanced topics such as ...

    Linux in a Nutshell 6th edition pdf

    "Linux in a Nutshell," Sixth Edition, thoroughly covers programming tools, system and network administration tools, the shell, editors, and LILO and GRUB boot loaders.

    SQL in a Nutshell

    SQL in a Nutshell讲述sql的基础知识,可能对大家有帮助。

Global site tag (gtag.js) - Google Analytics