Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

VBA - XML, selecting node values based on a variable

Avatar of meverts_dane
meverts_dane asked on
XML.NET Programming
1 Comment1 Solution8027 ViewsLast Modified:
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)
ASKER CERTIFIED SOLUTION
Avatar of meverts_dane
meverts_dane

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answers