Xquery 使用 解析文本标签

发布于 2024-09-07 08:18:56 字数 542 浏览 2 评论 0原文

我正在使用 XQuery 从 html 页面中提取内容。 html 主体结构是这样的:

 <td>
      <a href ="hw1">xyz </a>
          Hello world 1 
        <a href="hw2">Helloworld 2</a>
          Helloworld 3         
 </td>

我用于提取文本的 XQuery 表达式如下:

  //a[starts-with(@href,'hw1')]/following-sibling::text()

这个表达式给了我:

Helloworld 1 Helloworld 2 Helloworld 3

我想以这种方式拥有它: Helloworld 1 Helloworld 2 Helloworld 3 或 Helloworld 1 Helloworld 3

如何指定解析标签包含的文本

I am using XQuery to extract content from html pages. The html body structure is of this kind:

 <td>
      <a href ="hw1">xyz </a>
          Hello world 1 
        <a href="hw2">Helloworld 2</a>
          Helloworld 3         
 </td>

My XQuery expression for extracting the text is as follows:

  //a[starts-with(@href,'hw1')]/following-sibling::text()

This expression gives me :

Helloworld 1 Helloworld 2 Helloworld 3

I would like to have it in this fashion:
Helloworld 1 Helloworld 2 Helloworld 3 or
Helloworld 1 Helloworld 3

How do I specify to parse the text enclosed by tags

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

贱人配狗天长地久 2024-09-14 08:18:56

我不太清楚您在寻找什么,但

let $content := 
 <td>
      <a href ="hw1">xyz </a>
          Hello world 1 
        <a href="hw2">Helloworld 2</a>
          Helloworld 3         
 </td>

return $content/text()

直接在 下为您提供了文本节点。我没有看到你得到的和你想要的之间有什么区别......也许你的帖子丢失了一些格式?

I'm not really clear what you're looking for, but

let $content := 
 <td>
      <a href ="hw1">xyz </a>
          Hello world 1 
        <a href="hw2">Helloworld 2</a>
          Helloworld 3         
 </td>

return $content/text()

gives you the text nodes directly under the <td>. I don't see a difference between what you're getting and what you want... perhaps your post lost some formatting?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文