Testing text() nodes vs string values in XPath

前端 未结 1 976
半阙折子戏
半阙折子戏 2020-11-22 04:12

I have a node as follows:

Office Hours

For the XPath I use

//span         


        
相关标签:
1条回答
  • 2020-11-22 04:52

    XPath text() = is different than XPath . =

    (Matching text nodes is different than matching string values)

    The following XPaths are not the same...

    1. //span[text() = 'Office Hours']

      Says:

      Select the span elements that have an immediate child text node equal to 'Office Hours`.

    2. //span[. = 'Office Hours']

      Says:

      Select the span elements whose string value is equal to 'Office Hours`.

    In short, for element nodes:

    The string-value of an element node is the concatenation of the string-values of all text node descendants of the element node in document order.

    Examples

    The following span elements would match only #1:

    • <span class="portal-text-medium">Office Hours<br/>8:00-10:00</span>
    • <span class="portal-text-medium">My<br/>Office Hours</span>

    The following span elements would match only #2:

    • <span class="portal-text-medium"><b>Office</b> Hours</span>
    • <span class="portal-text-medium"><b><i>Office Hours</i></b></span>

    The following span element would match both #1 and #2:

    • <span class="portal-text-medium">Office Hours</span>
    0 讨论(0)
提交回复
热议问题