VBS and selectSingleNode and getAttribute...


I have a question that you all may be able to assist with.  I've done this in JScript but I'm missing something and not exactly sure how to achive this in VBScript.  

I want to get a attribute of a node.  In JScript I would do something like:

xObj = new ActiveXObject("Microsoft.XMLDOM");
var root = xObj.selectSingleNode("testOutput/test");  // Get the child node "test"
var strDesc = root.getAttribute("Description")

How do I do something similar to this in VBS.  I know in VB I can have the strDesc definied as and IXMLDOMElement but in VBS you can't create something with an AS on the DIM statement.  

Any assistance with this would be greatly appreciated.

Who is Participating?
joeposter649Connect With a Mentor Commented:
set xObj =CreateObject("Microsoft.XMLDOM")
root = xObj.selectSingleNode("testOutput/test")
strDesc = root.getAttribute("Description")
davismAuthor Commented:

Thanks for the info...I did infact try that before and on the root = xObj.selectSingleNode("testOutput/test") I got the message that the "Object is not set".

Now, if I do a "set root = xObj.selectSingleNode("testOutput/test") then that works but then I get an object required on strDesc.line referencing "root" needs to be defined.

Any ideas on this?
How about this...

set xObj =CreateObject("Microsoft.XMLDOM")
set root = xObj.selectSingleNode("testOutput/test")
set att= root.getAttribute("Description")
strDesc = att.value

Here's a pretty good reference...
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

davismAuthor Commented:
As I suspected on the line that is:

set att= root.getAttribute("Description")

I get a message saying "Object required: 'root'"

That means I can't even get to the att.value portion.  

The reference you gave me is great and I saw that one before but it illustrates it on the getAttribute method back to javascript not VBScript.  

Any other ideas?

Your assistance is greatly appreciated.
davismAuthor Commented:
I'm not sure why or how at this point but when I tried it again it is suddenly working.  I don't know if it was a typo although I don't recall changing anything.

Could it be something with the file loading into the parser?  Or failure to have that completed successfully?
davismAuthor Commented:
Got it working!  

Thanks for the info!  

Appreciate it very much.
All Courses

From novice to tech pro — start learning today.