Solved

VBS and selectSingleNode and getAttribute...

Posted on 2004-09-12
7
3,250 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now