Solved

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

Posted on 2004-09-16
2
2,716 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
2 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

22 Experts available now in Live!

Get 1:1 Help Now