[英]Edit attribute values of XML using VB6
我需要使用VB6更新bkp_path的屬性值。
<ServerDetails>
<Param src_path = "D:\Shapes\Rectangle" bkp_path = "D:\Colors\Red"/>
</ServerDetails>
我可以使用從XML文件讀取值
Dim doc As New MSXML2.DOMDocument
Set doc = New MSXML2.DOMDocument
Dim success As Boolean
'Load Config.xml
success = doc.Load("\Config\config.xml")
If success = False Then
MsgBox ("Unable to locate the configuration file")
Exit Function
Else
Dim nodeList As MSXML2.IXMLDOMNodeList
Set nodeList = doc.selectNodes("/ServerDetails/Param")
If Not nodeList Is Nothing Then
Dim node As MSXML2.IXMLDOMNode
For Each node In nodeList
srcpath = node.selectSingleNode("@src_path").Text
bkpPath = node.selectSingleNode("@bkp_path").Text
Next node
End If
End If
但無法弄清楚如何更新屬性值。
您需要獲取對節點對象的引用,然后調用setAttribute()
來指定新值:
node.setAttribute "bkp_path", "wibble"
您的代碼還從所有Param
節點讀取值,但是您可能只想使用第一個或更新特定的值。
這達到了目的:
node.selectSingleNode("@bkp_path").Text = "D:\\Colors\\Blue"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.