根据属性和节点值提取节点 [英] Extract nodes based on attribute and node values

查看:43
本文介绍了根据属性和节点值提取节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于下面的 XML,我试图根据属性和节点值提取节点.

For the below XML, I'm trying to extract the nodes based on attribute and node values.

基于属性 class=pass 和 h1 包含 ('objectives'),我试图提取以下输出.

Based on attribute class=pass and h1 contains ('objectives'), I'm trying to extract the below output.

objectives"是节点值字符串1个任务目标"的一部分

"objectives" is a part of the node value string "1 task objectives"

1 任务目标对象 1对象2

1 task objectives object1 object2

<body>
  <article>
    <body>
      <section>
        <h1>intro1</h1>
        <region>introd1</region>
        <region>introd2</region>
      </section>
      <section>
        <h1 class="pass">1 task objectives</h1>
        <region>object1</region>
        <region>object2</region>
      </section>
    </body>
  </article>
</body>

下面是我正在尝试的 XPath 表达式.但是,这并没有给出任何输出.你能指出我做错了什么吗?

Below is the XPath expression I am trying. However, this is not giving any output. Can you please point out what I am doing wrong?

//body//section//h1[contains(.,'objectives') and @class="pass"]/*/text()

谢谢&问候,西马克

Thanks & Regards, Simak

推荐答案

试试这个:

//body/section/h1[contains(.,'objectives') and @class='pass']/..//text()

这篇关于根据属性和节点值提取节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆