创建完成xml文件以后需要vba读取,一下则是vba读取xml文件过程。
Dim xmlDoc, xmlRoot, ChildItem, msg
Set xmlDoc = CreateObject ("Microsoft.XMLDOM")
xmlDoc.Load "C:\Documents and Settings\Administrator\Desktop\test\web.xml" '使用load方法来加载xml文档,建立dom树和xml文档之间的关联
Set xmlRoot = xmlDoc.documentElement '获取XML文档的根元素节点
For Each ChildItem In xmlRoot.childNodes
MsgBox "当前节点是:" & ChildItem.baseName '显示当前节点的名称
Set node1=ChildItem.childNodes.item(0)
If ChildItem.baseName = "title" Then
aa = node1.nodeValue
MsgBox aa
End If
'MsgBox node1.nodeValue
Next
代码也比较简单,只是一个简单的demo,离实现还有一定距离,继续深入。。。
补充:
Set xmldoc = CreateObject("Microsoft.XMLDOM")
xmldoc.Load ("C:\Users\IBM_ADMIN\Desktop\test.xml")
Set note = xmldoc.getElementsByTagName("root")
lsh = note.Length
Dim MyArray(1)
For i = 0 To lsh - 1
MyArray(0) = note.Item(0).getElementsByTagName("BpmName").Item(0).Text
MyArray(1) = note.Item(0).getElementsByTagName("searchDate").Item(0).Text
Next
MsgBox MyArray(0)
MsgBox MyArray(1)
xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<BpmName>1</BpmName>
<searchDate>2</searchDate>
</root>