我需要在 Excel 中的 VBA 中打开一个 XML 文件。我在 XML 文件中查找两个数据字符串,它们位于一个标签下。虽然这些字符串可以在多个标签下找到,但我还需要将它们连接起来。
<Systems>
<conveyor ConveyorNumber="132000">
<conveyor>132000</conveyor>
<productName>IQ</productName>
</conveyor>
</Systems>
里面的数据比较多,不过我只需要
<conveyor>132000</conveyor>
&
<productName>IQ</productName>
.有多个
<Systems></Systems>
在文件中,所以我需要计算文件中的系统连接所需的两个字符串并将它们全部放在 Excel 工作表的列中。有办法做到这一点吗?
最佳答案
尝试下面的代码来解析 XML 文件
Sub parseXML()
Dim strPath As String
strPath = Application.GetOpenFilename
Dim XDoc As Object
Set XDoc = CreateObject("MSXML2.DOMDocument")
XDoc.async = False
XDoc.validateOnParse = False
XDoc.Load (strPath)
Set xObjDetails = XDoc.ChildNodes(0)
Set xObject = xObjDetails.FirstChild
For Each xObject In xObjDetails.ChildNodes
MsgBox "Child nodes count " & xObjDetails.ChildNodes.Length
For Each xChild In xObject.ChildNodes
MsgBox xChild.BaseName & " " & xChild.Text
Next xChild
Next xObject
End Sub
关于xml - 使用 VBA 在 XML 文件中动态搜索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19729601/