Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBS and selectSingleNode and getAttribute...

Posted on 2004-09-12
7
Medium Priority
?
3,613 Views
Last Modified: 2012-05-05
All,

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");
xObj.Load("test.xml")
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.

Thanks
0
Comment
Question by:davism
  • 4
  • 3
7 Comments
 
LVL 15

Accepted Solution

by:
joeposter649 earned 500 total points
ID: 12043688
set xObj =CreateObject("Microsoft.XMLDOM")
xObj.Load("test.xml")
root = xObj.selectSingleNode("testOutput/test")
strDesc = root.getAttribute("Description")
0
 
LVL 1

Author Comment

by:davism
ID: 12043850
joeposter649,

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?
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12044144
How about this...

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

Here's a pretty good reference...
http://devguru.com/Technologies/xmldom/quickref/xmldom_index.html
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:davism
ID: 12044218
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.
0
 
LVL 1

Author Comment

by:davism
ID: 12047024
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?
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 12047261
0
 
LVL 1

Author Comment

by:davism
ID: 12061301
Got it working!  

Thanks for the info!  

Appreciate it very much.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question