如何选择节点的第一个子名称? X路径
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你写道:
您可以使用:
然后,您还写了:
所以,你可以使用:
You wrote:
You could use:
Then, you also wrote:
So, you could use:
我不知道您的 XML 的确切上下文,但我相信这是您正在寻找的 XPath...
该 XPath 的关键部分是
*[1]
,它将选择节点Department
第一个子级的值。如果您需要节点的名称,那么您将需要使用这个......
I don't know the exact context of your XML, but I believe this is the XPath you are looking for...
The key part of this XPath is
*[1]
, which will select the node value of the first child ofDepartment
.If you need the name of the node, then you will want to use this...
你需要类似的东西:
You need something like: