?
Solved

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

Posted on 2004-09-16
2
Medium Priority
?
2,791 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

Industry Leaders: 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 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. 
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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