VBA - XML, selecting node values based on a variable
I have written the following code.
The code works if provide the search criteria as text, however I want to load it as a parameter that will be supplied at runtime.
Dim paNode As XmlNode = node.SelectSingleNode("//Tags/Tag[@Name='Alarm'']")
I would like to figure out how to do something like this.
Dim paNode As XmlNode = node.SelectSingleNode("//Tags/Tag[@Name='ParameterName'']")
Dim filename As String filename = "C:\share\MikesTestFile.xml" Dim tagAttName As String tagAttName = "Alarm" Dim doc As XmlDocument = New XmlDocument() doc.Load(filename) Dim nodeList As XmlNodeList = doc.SelectNodes("//Tag") Dim node As XmlNode For Each node In nodeList If node.Attributes("Name").Value.ToString = tagAttName Then ' removed node based on attribute. Dim paNode As XmlNode = node.SelectSingleNode("//Tags/Tag[@Name='Alarm'']") If paNode Is Nothing Then MessageBox.Show("not working") End If node.ParentNode.RemoveChild(paNode) 'Dim dspString As String = node.Attributes("Id").Value.ToString 'MessageBox.Show("I found this ID value:" & dspString) 'node.RemoveChild(node.SelectSingleNode("Genre")) End If Next doc.Save(filename)