Search code examples
domvbscriptselectsinglenodexml

How to pass attribute text as a variable to select a single node in xml using VBScript?


I'm trying to select a single node in an xml file using VBscript using the following code

Set node = xmlDoc.selectingSingleNode(".//node()[@name = 'anything']") 

This works perfectly if I write what I need to pass as a text.

But I need to pass this 'anything' as a variable X

I tried the following but neither is working

xmlDoc.selectingSingleNode(".//node()[@name = X]")
xmlDoc.selectingSingleNode(".//node()[@name = '&X&']")

Any suggestions are appreciated


Solution

  • Just concatenate properly:

    >> X = "abc"
    >> WScript.Echo ".//node()[@name = '" & X & "']"
    >>
    .//node()[@name = 'abc']