vb 读取xml文件内容
我的xml文件内容如下<?xmlversion="1.0"encoding="GB2312"?>-<overlays><Infonlatitude="0.9"nlongi...
我的xml文件内容如下
<?xml version="1.0" encoding="GB2312" ?>
- <overlays>
<Info nlatitude="0.9" nlongitude="0.2" Width="840"Height="630" />
</overlays>
谢谢
我想读出width和height的值,然后进行修改后再保存,不知道说清楚没 展开
<?xml version="1.0" encoding="GB2312" ?>
- <overlays>
<Info nlatitude="0.9" nlongitude="0.2" Width="840"Height="630" />
</overlays>
谢谢
我想读出width和height的值,然后进行修改后再保存,不知道说清楚没 展开
1个回答
展开全部
Private Sub Command1_Click()
Dim xDoc As Object
Dim xmlFile As String
Dim strWidth As String
Dim strHeight As String
Set xDoc = CreateObject("MSXML2.DOMDocument")
xmlFile = "C:\aa.xml"
xDoc.Load xmlFile
strWidth = xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(2).Text
strHeight = xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(3).Text
MsgBox ("Width=" & strWidth & " Height=" & strHeight)
xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(2).Text = "123"
xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(3).Text = "456"
xDoc.save (xmlFile)
End Sub
注意 你上面的XML中Width="840"Height="630" 要分开,改成:
Width="840" Height="630"
Dim xDoc As Object
Dim xmlFile As String
Dim strWidth As String
Dim strHeight As String
Set xDoc = CreateObject("MSXML2.DOMDocument")
xmlFile = "C:\aa.xml"
xDoc.Load xmlFile
strWidth = xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(2).Text
strHeight = xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(3).Text
MsgBox ("Width=" & strWidth & " Height=" & strHeight)
xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(2).Text = "123"
xDoc.selectSingleNode("overlays").selectSingleNode("Info").Attributes(3).Text = "456"
xDoc.save (xmlFile)
End Sub
注意 你上面的XML中Width="840"Height="630" 要分开,改成:
Width="840" Height="630"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询