I need to update the attribute value of bkp_path using VB6.
<ServerDetails>
<Param src_path = "D:\Shapes\Rectangle" bkp_path = "D:\Colors\Red"/>
</ServerDetails>
I'm able to read values from XML file using
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
but can't figure out how to update attribute values.
You need to get a reference to the node object then call setAttribute()
to specify the new value:
node.setAttribute "bkp_path", "wibble"
Your code also reads the values from all the Param
nodes but you may want to only use the first or update a specific one.
这达到了目的:
node.selectSingleNode("@bkp_path").Text = "D:\\Colors\\Blue"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.