从Hive/Spark中选择XML的值

发布于 2025-01-27 23:01:04 字数 337 浏览 2 评论 0原文

我有XML:

<info>
<infofield name "date">2022-01-01</infofield>
<infofield name "country">USA</infofield>
<infofield name "city">New York</infofield>
</info>

我想在XPATH上选择“纽约”,但是当我编写此查询时: 选择XPATH_STRING(正文,'info/infofield [3]/@name')我的结果是 - “城市”,我如何选择“纽约”?

I have xml:

<info>
<infofield name "date">2022-01-01</infofield>
<infofield name "country">USA</infofield>
<infofield name "city">New York</infofield>
</info>

I want select "New York" with xpath, but when i am write this query:
Select xpath_string(body,'info/infofield[3]/@name') my result is - "city", how i can select "New York"?

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

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

发布评论

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

评论(1

三生殊途 2025-02-03 23:01:04

简单的方法:

info/infofield[3]/text()

如果您想成为岸上,如果Infofield的顺序发生了变化,那么您仍然会得到TE City,这是更好的方法:

info/infofield[@name='city']/text()

The easy way:

info/infofield[3]/text()

If you want to be shore that if the sequence of infofields changes, you still get te city this is the better way:

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