xpath - RIP Tutorial from: xpath It is an unofficial and free xpath ebook created for educational...

download xpath - RIP Tutorial from: xpath It is an unofficial and free xpath ebook created for educational purposes.

of 35

  • date post

    26-Jul-2020
  • Category

    Documents

  • view

    0
  • download

    0

Embed Size (px)

Transcript of xpath - RIP Tutorial from: xpath It is an unofficial and free xpath ebook created for educational...

  • xpath

    #xpath

  • 1

    1: xpath 2

    2

    2

    Examples 2

    XML 2

    2

    3

    HTML 3

    Xpath 3

    2: 5

    5

    Examples 5

    5

    5

    5

    “” 6

    6

    6

    3: 7

    7

    Examples 7

    7

    4: 8

    8

    8

    8

    Examples 8

    8

    8

    9

  • 9

    10

    10

    5: 11

    Examples 11

    11

    11

    6: 12

    Examples 12

    12

    7: 14

    Examples 14

    14

    14

    8: 16

    16

    16

    Examples 16

    16

    16

    16

    9: 18

    18

    18

    Examples 18

    Deborah 18

    Dobby 18

    10: 20

    20

    20

    20

  • Examples 20

    20

    21

    21

    21

    Parashurama 22

    Parashurama 22

    Parusharama 23

    House 24

    Room 24

    24

    11: 26

    26

    26

    26

    Examples 26

    26

    26

    12: 27

    27

    27

    27

    Examples 27

    LightDeviceSensor 27

    Light 27

    Star 28

    Ball 29

    light 30

    31

  • You can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: xpath

    It is an unofficial and free xpath ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official xpath.

    The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.

    Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to info@zzzprojects.com

    https://riptutorial.com/zh-CN/home 1

    http://riptutorial.com/ebook/xpath https://archive.org/details/documentation-dump.7z mailto:info@zzzprojects.com

  • 1: xpath

    XPathXML。

    XSLTXQuery。。

    XPathW3C

    XPath 1.0 XMLXPath1.0• XPath 2.0 XMLXPath2.0• XPath 3.0 XMLXPath3.0•

    1.0 1999-12-16

    2.0 2007-01-23

    3.0 201448

    3.1 W3C 20151217

    Examples

    XML

    XMLXPath

    Text 1 Text 2 Text 3 Text 4

    XML

    XPath

    /r/f/text()

    "Text 1"

    XPath

    https://riptutorial.com/zh-CN/home 2

    https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath/ https://www.w3.org/TR/xpath20/ https://www.w3.org/TR/xpath-30/ https://www.w3.org/TR/xpath-31/

  • string(/r/f)

    f

    "Text 1"

    XML

    XPath

    /r/e

    HTML

    HTML DOM

    link

    Element One

    Element Two

    ID

    //*[@id='divone'] # Returns

    ID

    /html/body/div/p[@id='enclosedone'] # Returns

    Element One

    id

    //p[@id='enclosedone' and @class='common'] # Returns

    Element One

    //*[@id='enclosedone']/text() # Returns Element One

    Xpath

    xpath。

    https://riptutorial.com/zh-CN/home 3

  • $x('//insert xpath here')

    $ - 。

    x - xpath

    $x("//button[text() ='Submit']")

    Submit。

    xpath https://riptutorial.com/zh-CN/xpath/topic/883/xpath

    https://riptutorial.com/zh-CN/home 4

    https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath https://riptutorial.com/zh-CN/xpath/topic/883/%E5%BC%80%E5%A7%8B%E4%BD%BF%E7%94%A8xpath

  • 2: XPath /

    step1/step2/step3

    。 ::。

    axis::nodeTest[predicate1][predicate2]

    /。N

    N• •

    。•

    Examples

    child

    /child::html/child::body/child::div/child::span

    child

    /html/body/div/span

    descendantdescendant-or-self。 child。

    /child::html/descendant::span /child::html/descendant-or-self::*

    ///descendant-or-self::node()/。

    table//td child::table/descendant-or-self::node()/child::td child::table/descendant::td table/descendant::td

    parent。htmlbody

    /child::html/child::body/parent::html

    ..parent::node()

    ancestorancestor-or-self。div

    https://riptutorial.com/zh-CN/home 5

  • ancestor::div

    “”

    self。.self::node()。.。

    .//span self::node()/descendant-or-self::node()/child::span descendant::span

    selfXPath 1.0。h1 h2h3

    *[self::h1 or self::h2 or self::h3]

    following-siblingpreceding-siblingfollowingpreceding

    。• following。• preceding。•

    following::span[1] following-sibling::*[last()]

    attributenamespace。@attribute::

    child::div/attribute::class div/@class

    https://riptutorial.com/zh-CN/xpath/topic/6171/

    https://riptutorial.com/zh-CN/home 6

    https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4 https://riptutorial.com/zh-CN/xpath/topic/6171/%E4%BD%8D%E7%BD%AE%E8%B7%AF%E5%BE%84%E5%92%8C%E8%BD%B4

  • 3:

    XPath 1.0。

    XMLXPath - XPathXPath。

    Examples

    /rootroot。。

    /*[namespace-uri() = 'http://test/' and local-name() = 'root']

    https://riptutorial.com/zh-CN/xpath/topic/2324/

    https://riptutorial.com/zh-CN/home 7

    https://riptutorial.com/zh-CN/xpath/topic/2324/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4 https://riptutorial.com/zh-CN/xpath/topic/2324/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4 https://riptutorial.com/zh-CN/xpath/topic/2324/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4 https://riptutorial.com/zh-CN/xpath/topic/2324/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4 https://riptutorial.com/zh-CN/xpath/topic/2324/%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4

  • 4: / path/ element [@attribute_name]•1. // * [@]•2. / path to / element [@ attribute_name ='search value']• / path to / element [@ attribute_name =“search value”]•

    3.

    // * [@ attribute_name ='']• // * [@ attribute_name =“”]•

    4.

    @attribute_name

    [@attribute_name]。

    starts-withlowercase。

    Examples

    XML

    Milky Way

    XPATH

    /Galaxy/*[@name]

    //*[@name]

    OUTPUT

    XML

    Milky Way

    XPATH

    https://riptutorial.com/zh-CN/home 8

  • /Galaxy/*[@name='Sun']

    //*[@name='Sun']

    OUTPUT

    XML

    Milky Way

    XPATH

    /Galaxy/*[contains(@name,'Ear')]

    //*[contains(@name,'Ear')]

    /Galaxy/*[contains(@name, "Ear")]

    OUTPUT

    XML

    Milky Way

    XPATH

    /Galaxy/*[contains(lower-case(@name),'ear')]

    //*[contains(lower-case(@name),'ear')]

    //*[contains(lower-case(@name), "ear")]

    OUTPUT

    https://riptutorial.com/zh-CN/home 9

  • XML

    Milky Way

    XPATH

    /Galaxy/*[starts-with(lower-case(@name),'ear')]

    //*[starts-with(lower-case(@name),'ear')]

    OUTPUT

    XML

    Milky Way

    XPATH

    /Galaxy/*[ends-with(lower-case(@type),'tar')]

    //*[ends-with(lower-case(@type),'tar')]

    OUTPUT

    ht