我有一个类似于以下结构的 XML 文件:
<egh_eval>
<eval_set>
<eval_id>FLOAT</eval_id>
<eval_d>
<height>INT</height>
<weight>INT</weight>
</eval_d>
<eval_e>
<height>INT</height>
<weight>INT</weight>
</eval_e>
<eval_cred>
<credit>FLOAT</credit>
</eval_cred>
</eval_set>
我需要解析完整的文件并将其放在一个表中。(注意:eval_d 和 eval_e 实际上各有一百多个属性)。我尝试使用 MSXML2,但是当我尝试解析文件时卡住了。通过使用如何在 VBA 中粘贴 XML 和在 VBA 中解析XML 中的答案,我能够到达那里:
Dim fSuccess As Boolean
Dim oDoc As MSXML2.DOMDocument
Dim oRoot As MSXML2.IXMLDOMNode ' Level 0 egh_eval
Dim oChild As MSXML2.IXMLDOMNode ' Level 1 eval_set
Dim oChildren As MSXML2.IXMLDOMNode ' Level 2 eval_id, eval_d, eval_e, eval_cred
Dim domList As MSXML2.IXMLDOMNodeList
Set oDoc = New MSXML2.DOMDocument
oDoc.async = False
oDoc.validateOnParse = False
fSuccess = oDoc.Load(Application.CurrentProject.Path & "\file.xml")
Set oRoot = oDoc.documentElement
Set oChild = oRoot.childNodes(0)
Set oChildren = oChild.childNodes(0)
For i = 0 To oChild.childNodes.length - 1
For y = 0 To oChildren.childNodes.length - 1
MsgBox oChildren.nodeName & " : " & oChildren.nodeTypedValue
oChildren.childNodes.nextNode
Next
oChild.childNodes.nextNode
Next
但是,它没有给我正确的值,而是给了我 eval_id 中的浮点数 4 次...
谢谢 !
编辑:我正在使用 Microsoft Access 2002 SP3