Solved

VBS and selectSingleNode and getAttribute...

Posted on 2004-09-12
7
3,291 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 125 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

776 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