VB语言中XML对象(Microsoft.XMLDOM)的属性、方法、事件有哪些
答案:3 悬赏:50 手机版
解决时间 2021-07-31 17:18
- 提问者网友:别再叽里呱啦
- 2021-07-31 06:47
VB语言中XML对象(Microsoft.XMLDOM)的属性、方法、事件有哪些?
它们的用法?
如果是 【Ctrl+V】过来的请注明源处。
好的话加分。
最佳答案
- 五星知识达人网友:你可爱的野爹
- 2021-07-31 07:08
我以前用到的一个实例
Private Sub LoadXML()
'Xml文件结构如下:
' <?xml version="1.0" encoding="gb2312" ?>
'- <test>
' <type name="古典武侠">侠义天下</type>
'- <book name="寻秦记" author="黄易" price="25">
' <chapter2 title="科学疯子" page="87">被拉过去当实验品</chapter2>
' <chapter3 title="阴错阳差" page="44">实验失败,来到了三年前秦国</chapter3>
' <chapter4 title="美蚕娘" page="26">在荒野山村遇到美蚕娘</chapter4>
' </book>
' </test>
Dim xmlDom As New DOMDocument
Dim xmlNode As IXMLDOMElement
Dim i As Integer
xmlDom.Load (App.Path + "\xml.xml")
Set xmlNode = xmlDom.documentElement.childNodes(1)
If xmlDom.documentElement Is Nothing Then
Exit Sub
End If
ListView1.ListItems.Clear
With ListView1.ColumnHeaders
.Clear
.Add , , "章节"
.Add , , "题目"
.Add , , "页数"
.Add , , "内容简介"
.Item(1).Width = 1000
.Item(2).Width = 1000
.Item(3).Width = 600
.Item(4).Width = 1750
End With
For i = 0 To xmlNode.childNodes.length - 1
With ListView1.ListItems.Add(, , xmlNode.childNodes(i).nodeName)
.SubItems(1) = xmlNode.childNodes(i).Attributes(0).Text
.SubItems(2) = xmlNode.childNodes(i).Attributes(1).Text
.SubItems(3) = xmlNode.childNodes(i).Text
End With
Next
End Sub
------------------------------------------------------------------------------------------------------------
Dim objXML As DOMDocument
Dim nXML As Node
Dim childnode As Node
Dim secondnode As Node
Private Sub Command1_Click()
'xmlDom object
'Set objXML = CreateObject("Microsoft.XMLDOM")
Set objXML = New DOMDocument
objXML.async = False
'load the xml menu file
objXML.Load ("mysites.xml")
Set objLst = objXML.getElementsByTagName("site")
'how many items
intNoOfHeadlines = objLst.length
'looping over the items -1 because it's starts from 0 Set nXML = TreeView1.Nodes.Add(, , "root", "站点信息")
'Call LoadTree(nXML, children)
For i = 0 To intNoOfHeadlines - 1
Set objHdl = objLst.Item(i)
key1 = "p" & i
Set childnode = TreeView1.Nodes.Add(nXML, tvwChild, "", objHdl.childNodes(0).Text)
Set secondnode = TreeView1.Nodes.Add(childnode, tvwChild, "", objHdl.childNodes(1).Text)
'List2.AddItem objLst.Item(i).Attributes(i).Text
'List3.AddItem objHdl.childNodes(2).Text
Next
End Sub
mysites.xml
<?xml version="1.0"?>
<mysites>
<site>
<topic>news</topic>
<name>CNN</name>
<url> http://www.cnn.com</url>
</site>
<site>
<topic>sport</topic>
<name>Sydney 2000</name>
<url> http://www.olympics.com</url>
</site>
<site>
<topic>Travel</topic>
<name>VirtualTourist</name>
<url> http://www.virtultourist.com</url>
</site>
<site>
<topic>computers</topic>
<name>Experts-exchange</name>
<url> http://www.experts-exchange.com</url>
</site>
<site>
<topic>computers</topic>
<name>Microsoft</name>
<url> http://www.microsoft.com</url>
</site>
<site>
<topic>sport</topic>
<name>Sportelo</name>
<url> http://www.sportelo.co.il</url>
</site>
<site>
<topic>computers</topic>
<name>myscript</name>
<url> http://www.myscript.co.il</url>
</site>
</mysites>
全部回答
- 1楼网友:污到你湿
- 2021-07-31 09:58
好
- 2楼网友:蕴藏春秋
- 2021-07-31 08:44
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯