如何选择节点的第一个子名称? X路径

发布于 2024-09-17 10:29:38 字数 231 浏览 3 评论 0原文

我有一个 XML,必须从中选择其中一个节点的子节点的名称。我是这方面的初学者,所以我没有找到 Xpath 表达式来做到这一点。 Name的级别

的节点Example

我知道来自 /Employee/Department/

,但 Department 具有未知名称的子节点。我必须选择 Department 节点的第一个子节点。我该怎么做?

I have an XML from which I have to select the name of the child of one of the nodes. I'm kind of a beginner in this, so I didn't find the Xpath expression to do it. I know the level of the node

Example

Name from /Employee/Department/

but Department has children nodes of unknown names. I have to select the first child of Department node. How can I do this?

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

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

发布评论

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

评论(3

固执像三岁 2024-09-24 10:29:38

你写道:

我必须选择第一个孩子
部门节点

您可以使用:

/Employee/Department/*[1]

然后,您还写了:

我有一个 XML,我必须从中获取
选择其中之一的孩子的名字
节点

所以,你可以使用:

name(/Employee/Department/*[1])

You wrote:

I have to select the first child of
Department node

You could use:

/Employee/Department/*[1]

Then, you also wrote:

I have an XML from which I have to
select the name of the child of one of
the nodes

So, you could use:

name(/Employee/Department/*[1])
且行且努力 2024-09-24 10:29:38

我不知道您的 XML 的确切上下文,但我相信这是您正在寻找的 XPath...

/Employee/Department/*[1]

该 XPath 的关键部分是 *[1],它将选择节点Department 第一个子级的值。

如果您需要节点的名称,那么您将需要使用这个......

name(/Employee/Department/*[1])

I don't know the exact context of your XML, but I believe this is the XPath you are looking for...

/Employee/Department/*[1]

The key part of this XPath is *[1], which will select the node value of the first child of Department.

If you need the name of the node, then you will want to use this...

name(/Employee/Department/*[1])
爱的故事 2024-09-24 10:29:38

你需要类似的东西:

local-name(/Employee/Department/*[1])

You need something like:

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