使用 Excel VBA 查询 XML 文档

发布于 2024-10-03 04:27:36 字数 515 浏览 0 评论 0原文

我正在构建需要使用 SelectNodes(xpath) 从 XML 文档加载的节点列表:

Set oNodeList = xmldoc.selectNodes("//Object/Property[@Name='Group' and Value='True']")

并循环遍历节点:

For Each curNode In oNodeList
  Set nAttr = curNode.parentNode.Attributes
  If (nAttr.getNamedItem("Seq").nodeValue = "abc") Then
'  additional processing
  End If
Next

附加处理涉及循环遍历 curNode 的子节点。我想知道是否可以使用 selectNodes 构建另一个 nodeList,它会选择满足特定条件的 curNode 的子节点。关键点是xpath应该从当前节点开始查找。

我怎样才能做到这一点?

I'm building a list of nodes I need to load from XML document using SelectNodes(xpath):

Set oNodeList = xmldoc.selectNodes("//Object/Property[@Name='Group' and Value='True']")

and looping thru the nodes:

For Each curNode In oNodeList
  Set nAttr = curNode.parentNode.Attributes
  If (nAttr.getNamedItem("Seq").nodeValue = "abc") Then
'  additional processing
  End If
Next

Additional processing involves looping thru child nodes of curNode. I was wondering if it's possible in build yet another nodeList using selectNodes which would select child nodes of curNode that meet particular criteria. The key point that xpath should start looking from the current node.

How can I do that?

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

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

发布评论

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

评论(1

为你拒绝所有暧昧 2024-10-10 04:27:45

亚历杭德罗,谢谢你!看起来好像

curNode.Selectnodes("child::*")

是有窍门!

Alejandro, thank you! It seems like

curNode.Selectnodes("child::*")

does the trick!

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