0

I am trying to update node values in a .xml file using a loop.

The oXMlFile.SelectSingleNode line shown correctly updates a single node, but I don't know how to modify the code so that I can loop though all the nodes and update the values.

Any help would be appreciated.

Set oXMLFile = CreateObject("Microsoft.XMLDOM")
oXMLFile.Load (ConfigFile)

'Update Node Attributes

Dim ii, TotChan As String
 ii = 0
 TotCh = 500

 Do While (ii < TotCh - 1)


Set CalibrationDateTimeNode=oXMLFile.SelectSingleNode("/HConfig/Signal[0]/CalibrationDateTime")

CalibrationDateTimeNode.Text = "2016-04-16"

 ii = ii + 1
 Loop

1 Answer 1

1

I'm not quite sure what you exactly need, but to loop through xml nodes, use this:

Dim calibrationDateTimeNode As IXMLDOMNode
Dim colNodes As IXMLDOMNodeList

Set colNodes = oXMLFile.selectNodes("/HConfig/Signal[0]/...WhateverYouNeed")
For Each CalibrationDateTimeNode In colNodes
   CalibrationDateTimeNode.Text = "2016-04-16"
Next

The SelectNodes command can selet a node list, and then you can iterate its elements. Using a for each makes it a lot easier than a do-while. Not to mention faster, if I'm not mistaken.

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

1 Comment

Thanks, that is what I needed and everything works now.

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.