1 打开VB6.0 File--->New Project---->Standard ExE---->OK
2 打开菜单Project---->Reference---->选中Microsoft XML,V6.0---->OK
3 打开菜单Project---->Components---->选中Microsoft Windows Common Controls 6.0---->确定,
4 新建如下的Form
5 在Form_Load 下添加代码
ListView1.ColumnHeaders.Add , , "Flow", ListView1.Width / 2
ListView1.ColumnHeaders.Add , , "Number", ListView1.Width / 2
ListView1.View = lvwReport
6 在CreateXML按钮下添加代码,新建一个XML文件
Dim XmlDoc As DOMDocument
Set XmlDoc = New DOMDocument
XmlDoc.loadXML "<Data><Flow><Name>车加工</Name><Number>1</Number></Flow><Flow><Name>铣加工</Name><Number>2</Number></Flow></Data>"
XmlDoc.save "d:\flow.xml"
7在ReadXML按钮下添加代码
Dim XmlDoc As DOMDocument
Dim XMlRoot As IXMLDOMNode, XmlNode As IXMLDOMNode, XmlFor As IXMLDOMNode
Dim XmlList As IXMLDOMNodeList, XmlListFor As IXMLDOMNodeList
Dim i As Integer
Set XmlDoc = New DOMDocument
XmlDoc.Load "d:\flow.xml"
Set XmlNode = XmlDoc.selectSingleNode("Data")
Set XmlList = XmlNode.childNodes
ListView1.ListItems.Clear
For Each XmlFor In XmlList
Set XmlListFor = XmlFor.childNodes
With ListView1.ListItems.Add(, , XmlListFor.Item(0).Text)
.SubItems(1) = XmlListFor.Item(1).Text
End With
Next
7 F5运行,先点击CreateXML按钮,在点击ReadXML按钮,所得运行结果如图
8 打开D盘下的Flow.xml文件,我们可以看到XML文件内容
9 END