Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vbscript & selectSingleNode() - XPATH query not getting desired results

Posted on 2004-09-16
2
Medium Priority
?
2,823 Views
Last Modified: 2008-01-09
Hello,
This question is urgent but probably not difficult.

I need someone to give me the correct syntax for my xpath query.

Basically I want to grab the <desired> node and its associated attributes. Since it is at the root level in vbscript I tried to get it with:
set node = objXmlDoc.documentElement.selectSingleNode("//desired")
* I also tried leaving the syntax("//") inside the selectSingleNode but I kept getting back nothing.

after googling xpath I came across something that led me to beleive I may not be able to access the <desired> node because of its position. If this is true I would then move <desired> inside element :<element><desired name= etc/></element> I also tried a similar xpath query for that("//element/desired") but I kept getting an error.

Can anyone show me an vbscript selectSingleNode call with valid xpath syntax that would get my desired nodes?

<root>
<desired name="bob" computername="winbox"/>
<element>
</element>
<another_element>
</another_element>
</root>
0
Comment
Question by:barryk2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 1500 total points
ID: 12077487
How are you loading the XML?  I copied the XML into a file and ran your selectSingleNode line as written above and it returns the correct node.

Here's my script (XMLFile2.xml is in same directory as script file):

   path = "XMLFile2.xml"
    Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
    objXMLDoc.async = False
    objXMLDoc.load(path)
    WScript.Echo "xml document loaded"
   set node = objXmlDoc.documentElement.selectSingleNode("//desired")
   WScript.Echo node.nodeName
0
 

Author Comment

by:barryk2
ID: 12077866
Weird- it must have been a typo on my part that this did not worked. My original code worked. Thanks for the help
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

604 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