2

I need to update the attribute value of bkp_path using VB6.

XML File

<ServerDetails>
    <Param src_path = "D:\Shapes\Rectangle" bkp_path = "D:\Colors\Red"/>
</ServerDetails>

I'm able to read values from XML file using

VB6 Code

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I'm looking to update a particular attribute not the first one, in this case 'bkp_path'. I've tried this earlier as well, didnt work.
I said node (<Param ...>), not the attribute (src_path =). The attributes (using this code) are referenced by name. The code you supplied reads the values from EVERY <Param> node, but I assume you only want to set one of them.
Yes, it should read each <Param> and update each bkp_path attribute. Finally, found the solution. This is what I was looking for : node.selectSingleNode("@bkp_path").Text = "D:\Colors\Blue" Anyways thank you for the prompt replies.
Which does the same as I suggested... If you've found your answer, please post it as an answer and accept it.
2

This did the trick :

node.selectSingleNode("@bkp_path").Text = "D:\Colors\Blue"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.