Solved

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

Posted on 2004-09-16
2
2,762 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

688 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