vb 读取xml文件内容

我的xml文件内容如下
<?xml version="1.0" encoding="GB2312" ?>
- <overlays>
<Info nlatitude="0.9" nlongitude="0.2" Width="840"Height="630" />
</overlays>
谢谢
我想读出width和height的值,然后进行修改后再保存,不知道说清楚没

第1个回答  推荐于2017-11-27
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"本回答被提问者采纳
相似回答