使用 XPath 提取两个标签之间的内容 [英] Extracting content between two tags with XPath

查看:46
本文介绍了使用 XPath 提取两个标签之间的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近刚开始使用 XPath,但遇到了一个问题.这是我想从中提取的代码:

I've just started working with XPath recently and run into a problem. Here is the code I want to extract from:

 <h3>Some Company</h3>
    Mainstreet 1234
 <br>
    98776, Country
 <br>

如何提取结束 h3 和 br 标签之间的内容?

How would I extract the content between the closing h3 and br tag?

推荐答案

这可以工作 h3/following-sibling::node()[not(preceding-sibling::br) and not(self::br))](为我返回Mainstreet 1234").

This could work h3/following-sibling::node()[not(preceding-sibling::br) and not(self::br)] (returns "Mainstreet 1234" for me).

但我担心您的真实 xml 和实际需求比提供的示例更复杂,因此您可能需要进一步调整它以满足您的要求.

But I'm affraid your real xml and real needs are more complicated than provided sample so it is possible you will need to further adjust it to fit you requirements.

这篇关于使用 XPath 提取两个标签之间的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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