你好我试图在xml节点之间循环但由于某种原因我只得到第一个节点任何想法将不胜感激! XML:
<root>
<AC>
<answer id ="c1">
blue
</answer>
<answer id ="c1">
blue
</answer>
</root>
VBA代码:
Set ques = getQues(qName) 'ques is in CreateObject("MSXML2.DOMDocument") format
Set nodes = ques.SelectNodes("/root/AC")
For Each node In nodes
MsgBox (node.SelectSingleNode("answer").Text)
Cells(i + 1, j).Value = node.SelectSingleNode("answer").Text
Next node
感谢您的帮助!
答案 0 :(得分:3)
您的selectnodes
仅选择AC
节点:看起来您真的想要选择answer
个节点的集合 -
Sub Tester()
Dim d As New MSXML2.DOMDocument
Dim nodes, nd
d.LoadXML Range("A1").Value
Set nodes = d.SelectNodes("/root/AC/answer")
For Each nd In nodes
Debug.Print nd.getAttribute("id"), nd.Text
Next nd
End Sub