一起选择 XML 节点将所有子节点

发布于 2024-10-06 17:49:17 字数 357 浏览 0 评论 0原文

我想从已加载的 XML 文档中选择一个节点及其所有子节点。我应该使用什么方法来获取,例如下面的 和所有子节点(子节点 2.1,2.2,2.3)?

<xmldoc>
  <item1>
    <child1.1>
    <child1.2>
    <child1.3>
  </item1>
  <item2>
    <child2.1>
    <child2.2>
    <child2.3>
  </item2>
</xmldoc>

I want to select a node together with all child nodes from an XML document that I have loaded. What method whould I use to get, for example below, <item2> and all child nodes (child 2.1,2.2,2.3)?

<xmldoc>
  <item1>
    <child1.1>
    <child1.2>
    <child1.3>
  </item1>
  <item2>
    <child2.1>
    <child2.2>
    <child2.3>
  </item2>
</xmldoc>

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

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

发布评论

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

评论(2

熊抱啵儿 2024-10-13 17:49:17

假设您需要(如问题中所述)选择 item2 及其所有子节点,XPath 表达式将为

xmldoc/item2 | xmldoc/item2/*

如果您需要所有后代 (例如对于更复杂的结构)

xmldoc/item2/descendant-or-self::*

Assuming you need (as mentioned in question) to select item2 and all its child nodes, XPath expression will be

xmldoc/item2 | xmldoc/item2/*

And if you need all descendants (e.g. for more complicated structure)

xmldoc/item2/descendant-or-self::*
酒解孤独 2024-10-13 17:49:17

xpath 表达式应为 /xmldoc/item2/*
否则你应该指定用什么语言......

The xpath expression should be /xmldoc/item2/*
Otherwise you should specify in what language...

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