xml檔案大概是這樣的結構
<Use logindate="10/23/2014">
<user 用戶ID="11" UserID="113" userEName="qwe"/>
..........
</Use>
怎么用VB更改userEName的屬性值,謝謝
uj5u.com熱心網友回復:
這個用的不多,參考著改吧:Sub ChangeXMLNodeAttribute()
Dim xmlDoc, xmlNode, xmlFile
xmlFile = "e:\xml.xml"
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = False
xmlDoc.Load xmlFile
If xmlDoc.parseError.errorCode <> 0 Then
MsgBox "打開錯誤:" & xmlDoc.parseError.reason
Exit Sub
End If
Set xmlNode = xmlDoc.documentElement.getElementsByTagname("user")
If xmlNode.length = 1 Then
If xmlNode(0).Attributes(2).Name = "userEName" Then
xmlNode(0).Attributes(2).Value = CStr(Timer) ''隨機值
xmlDoc.save xmlFile ''更新到檔案
End If
Else
MsgBox "有0或者多個節點....."
End If
Set xmlDoc = Nothing
Set xmlNode = Nothing
End Sub
uj5u.com熱心網友回復:
vb 操作xml轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/110965.html
標籤:VB基礎類
上一篇:水晶報表的問題
