使用 Excel VBA 查询 XML 文档
我正在构建需要使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
亚历杭德罗,谢谢你!看起来好像
是有窍门!
Alejandro, thank you! It seems like
does the trick!