Solved

VBS and selectSingleNode and getAttribute...

Posted on 2004-09-12
7
3,312 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

792 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