代码之家  ›  专栏  ›  技术社区  ›  Anas Laghouaouta

XPath返回由html标记拆分的字符串连接

  •  2
  • Anas Laghouaouta  · 技术社区  · 8 年前

    如何使用XPath表达式返回包含串联值的字符串值?

    <div>
    This text node (1) should be returned.
    <em>And the value of this element.</em>
    And this.
    </div>
    
    <div>
    This text node (2) should be returned.
    And this.
    </div>
    
    <div>
    This text node (3) should be returned.
    <em>And the value of this element.</em>
    And this.
    </div>
    

    div 元素:

    "This text node (1) should be returned. And the value of this element. And this."
    "This text node (2) should be returned. And this."
    "This text node (3) should be returned. And the value of this element. And this."
    

    这在单个XPath表达式中可能吗?

    1 回复  |  直到 8 年前
        1
  •  2
  •   kjhughes    8 年前

    XPath 1.0

    div 元素:

    //div
    

    然后对每个 部门 元素,该元素位于承载XPath库调用的语言中。

    XPath 2.0

    这个XPath 2.0表达式,

    //div/normalize-space()
    

    将返回所有 部门 文件中的元素:

    This text node (1) should be returned. And the value of this element. And this.
    This text node (2) should be returned. And this.
    This text node (3) should be returned. And the value of this element. And this.
    

    根据要求。