AD

XPath Tutorial - Introduction example of "one"

Based XPath1.0 standards introduced by the following 22 examples of XPath features. Basic XPath syntax is similar to a file system to locate files (below the red text indicates an instance of selection results)

1, if the path to slash / start, then the path to that element of the absolute path to a

(1). "/ AAA" that select the root element AAA:

<AAA>
<BBB/>
<CCC/>
<BBB/>
<BBB/>
<DDD>
<BBB/>
</ DDD>
<CCC/>
</ AAA>

(2). "/ AAA / DDD / BBB" said the child elements of AAA DDD select all child elements:

<AAA>
<BBB/>
<CCC/>
<BBB/>
<BBB/>
<DDD>
<BBB/>
</ DDD>
<CCC/>
</ AAA>

2, If the path to double slash / / at the beginning, then select the document for all to meet the double slash / / elements after the rules (regardless of level of relationship)

(1 )."// BBB "that select all BBB elements:

<AAA>
<BBB/>
<CCC/>
<BBB/>
<DDD>
<BBB/>
</ DDD>
<CCC>
<DDD>
<BBB/>
<BBB/>
</ DDD>
</ CCC>
</ AAA>

(2 )."// DDD / BBB "that selects all the parent element is the BBB DDD elements:

<AAA>

<BBB/>
<CCC/>
<BBB/>
<DDD>
<BBB/>
</ DDD>
<CCC>
<DDD>
<BBB/>
<BBB/>
</ DDD>
</ CCC>
</ AAA>

3, select the asterisk * indicates that all paths from the star before the elements of the positioning

(1). "/ AAA / CCC / DDD / *" Select all the paths that attached / AAA / CCC / DDD elements:

<AAA>
<XXX>
<DDD>
<BBB/>
<BBB/>
<EEE/>
<FFF/>
</ DDD>
</ XXX>
<CCC>
<DDD>
<BBB/>
<BBB/>
<EEE/>
<FFF/>
</ DDD>
</ CCC>
<CCC>
<BBB>
<BBB>
<BBB/>
</ BBB>
</ BBB>
</ CCC>
</ AAA>

(2). "/*/*/*/ BBB "that selects all the elements have three ancestors BBB elements:

<AAA>
<XXX>
<DDD>
<BBB/>
<BBB/>
<EEE/>
<FFF/>
</ DDD>
</ XXX>
<CCC>
<DDD>
<BBB/>
<BBB/>
<EEE/>
<FFF/>
</ DDD>
</ CCC>
<CCC>
<BBB>
<BBB>
<BBB/>
</ BBB>
</ BBB>
</ CCC>
</ AAA>

4, box number where the expression can be further specified elements, which figures that elements in the choice set in place, while last () function, said the last element of the selection focus

(1). "/ AAA / BBB [1]", said the first choice AAA BBB sub-elements:

<AAA>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
</ AAA>

(2). "/ AAA / BBB [last ()] ', said the final choice AAA BBB sub-elements:

<AAA>
<BBB/>
<BBB/>
<BBB/>
<BBB/>
</ AAA>

5, the property designated by the prefix @ to

(1 )."//id "that selects all the id attributes:

<AAA>
<BBB Id = "b1"/>
<BBB Id = "b2"/>
<BBB Name = "bbb"/>
<BBB/>
</ AAA>

(2 )."// BBB [@ id] "select id attribute that BBB elements:

<AAA>
<BBB Id = "b1"/>
<BBB Id = "b2"/>
<BBB Name = "bbb"/>
<BBB/>
</ AAA>

(3 )."// BBB [@*]" select any attribute that BBB elements:

<AAA>
<BBB Id = "b1"/>
<BBB Id = "b2"/>
<BBB Name = "bbb"/>
<BBB/>
</ AAA>

(4 )."// BBB [not (@*)]" said the BBB has no attributes selected elements:

<AAA>
<BBB Id = "b1"/>
<BBB Id = "b2"/>
<BBB Name = "bbb"/>
<BBB/>
</ AAA>

6, property values can be used as selection criteria, normalize-space function to delete the spaces in the front and rear, and replace the string of consecutive spaces into a single space

(1 )."// BBB [@ name = 'bbb'] "that contains the attribute name and select the value 'bbb' of BBB elements:

<AAA>
<BBB Id = "b1"/>
<BBB Name = "bbb "/>
<BBB Name = "bbb"/>
</ AAA>

(2 )."// BBB [normalize-space (@ name) = 'bbb'] "that contains the attribute name and choose its value (in use normalize-space function to remove spaces before and after the post) to 'bbb' of the BBB elements:

<AAA>
<BBB Id = "b1"/>
<BBB Name = "bbb "/>
<BBB Name = "bbb"/>
</ AAA>

7, count () function can count the number of selected elements

(1 )."//*[ count (BBB) = 2] ", said select element contains two child elements BBB:

<AAA>
<CCC>
<BBB/>
<BBB/>
<BBB/>
</ CCC>
<DDD>
<BBB/>
<BBB/>
</ DDD>
<EEE>
<CCC/>
<DDD/>
</ EEE>
</ AAA>

(2 )."//*[ count (*) = 2] ", said select element containing two sub-elements:

<AAA>
<CCC>
<BBB/>
<BBB/>
<BBB/>
</ CCC>
<DDD>
<BBB/>
<BBB/>
</ DDD>
<EEE>
<CCC/>
<DDD/>
</ EEE>
</ AAA>

8, name () function returns the element's name, start-with () function in the first argument of the function the second parameter character string is the situation began to return true, contains () function when its first string argument The second parameter contains the string returns true

(1 )."//*[ name () = 'BBB'] "said the BBB name to select all the elements (in this case is equivalent to / / BBB):

<AAA>
<BCC>
<BBB/>
<BBB/>
<BBB/>
</ BCC>
<DDB>
<BBB/>
<BBB/>
</ DDB>
<BEC>
<CCC/>
<DBD/>
</ BEC>
</ AAA>

(2 )."//*[ starts-with (name (), 'B')] "to select all names that" B "Start element:

<AAA>
<BCC>
<BBB/>
<BBB/>
<BBB/>
</ BCC>
<DDB>
<BBB/>
<BBB/>
</ DDB>
<BEC>
<CCC/>
<DBD/>
</ BEC>
</ AAA>

(3 )."//*[ contains (name (), 'C')] "Select all names that contain" C "element:

<AAA>
<BCC>
<BBB/>
<BBB/>
<BBB/>
</ BCC>
<DDB>
<BBB/>
<BBB/>
</ DDB>
<BEC>
<CCC/>
<DBD/>
</ BEC>
</ AAA>

9, string-length function returns the string of characters, you should use the "Substitution <, with"> instead of>

(1 )."//*[ string-length (name ()) = 3] "select name, said the length of 3 elements:

<AAA>
<Q/>
<SSSS/>
<BB/>
<CCC/>
<DDDDDDDD/>
<EEEE/>
</ AAA>

(2 )."//*[ string-length (name ()) <3] "that / / * [string-length (name ()) <3] (greater than the same applicable):

<AAA>
<Q/>
<SSSS/>
<BB/>
<CCC/>
<DDDDDDDD/>
<EEEE/>
</ AAA>

10, multiple paths can be delimited | merge

(1 )."// CCC | / / BBB "that selects all of the CCC and BBB elements:

<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</ DDD>
<EEE/>
</ AAA>

(2). "/ AAA / EEE | / / BBB" to select all of the BBB that element and all child elements of EEE AAA elements:

<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</ DDD>
<EEE/>
</ AAA>

(3). "/ AAA / EEE | / / DDD / CCC | / AAA | / / BBB", said the number of paths can be combined without restriction:

<AAA>
<BBB/>
<CCC/>
<DDD>
<CCC/>
</ DDD>
<EEE/>
</ AAA>

11, child-axis (axis) that contains the context node's child elements, as the default axis, can be neglected to write

(1). "/ Child:: AAA" is equivalent to / AAA:

<AAA>
<BBB/>
<CCC/>
</ AAA>

(2). "/ Child:: AAA / child:: BBB" is equivalent to / AAA / BBB:

<AAA>
<BBB/>
<CCC/>
</ AAA>

(3). "/ Child:: AAA / BBB":

<AAA>
<BBB/>
<CCC/>
</ AAA>
标签: lt, quot, gt 2, relationship, bbb, aaa, ddd, absolute path, ccc, fff, eee, asterisk, tutorial introduction, root element, child elements, parent element, xpath syntax, selection results
分类: Tech
时间: 2010-05-28

相关文章

  1. XPath Tutorial - Examples Introduction <2>

    12, descendant (offspring) axis contains the context node's descendants, a descendant is a child node or child ...
  2. XPath Tutorial - Example description <2>

    12, descendant (offspring) axis contains the context node's descendants, a descendant is a child node or child ...
  3. HttpClient Tutorial (Introduction)

    HTTP is probably today the most important use of Internet protocol. Web service, web enabled applications and ...
  4. ant Tutorial Introduction

    1 Ant What is this? Apache Ant is a Java-based build tool. Generation tool used in software development in the ...
  5. JFreeChart Tutorial - Introduction

    A, JFreeChart access. JFreeChart JFreeChart is in an open-source project on SourceForge.net site, the company' ...
  6. 01 primary articles Maven tutorial: Introduction

    Maven recent series of upcoming video tutorials, stay tuned to my blog! 1. Maven's starting point During the s ...
  7. XSL Introduction (reprint)

    XSL Languages Previous Page Next Page which began in XSL, the end of the XSLT, XPath and XSL-FO. Starting in X ...
  8. XSL Introduction (reproduced)

    XSL language Previous Page Next Page It began in XSL, ending in XSLT, XPath and XSL-FO. Starting in XSL XSL Ex ...
  9. Firebug Tutorial (Section 1)– Using Commandline API in Firebug (Part III)

    Firebug Tutorial – Using Commandline API in Firebug September 15, 2007 Firebug Tutorial Section 1: Console Tab ...
  10. Complete Hibernate 3.0 Tutorial

    This tutorial provide step by step instructions on using Hibernate 3.0. Hibernate is popular open source objec ...
  11. Original Tutorial Collection

    The following tutorial Guo Shaorui original tutorial, reproduced, please indicate the source (www.richbox.net ...
  12. The use of a collection of several Git tutorial

    The Project is using Git for version control tool, they would find some tutorials for beginners. Git Chinese t ...
  13. Android Service Tutorial

    Lars Vogel Version 2.6 Copyright © 2011, 2012, 2013 Lars Vogel 22.05.2013 Revision History Revision 0.1 07.03. ...
  14. 2000个软件开发领域的高频特殊词及精选例句(七)

    superword是一个Java实现的英文单词分析软件,主要研究英语单词音近形似转化规律.前缀后缀规律.词之间的相似性规律等等. 1701.单词 jpql 的匹配文本: You will learn how to imp ...
  15. java study information kept pushing

    JAVA Study Data (hematemesis recommend) A. Title: "Thinking in Java" 2e English version of Hou Jie / ...
  16. keep pushing java study information

    JAVA Study Data (hematemesis recommend) A. Title: "Thinking in Java" 2e English version of Hou Jie / ...
  17. Java SE technology

    What is Java technology? Java technology is both a high-level object-oriented programming language, but also a ...
  18. XML documents using Libxml2 operation

    1, Libxml2 Description: Libxml2 is an xml parser c-language version, was originally a tool for the Gnome proje ...
  19. AutoPager concise Raiders (3): Creating Rules

    Original Source: http://qixinglu.com/archives/autopager_tutorial_create_rule , slight changes. The article sai ...