Solved

vbscript and going through xml documents

Posted on 2004-09-07
4
273 Views
Last Modified: 2008-03-10
Hello,

I have an xml document that I would like to step through part of it and then search the rest of the document.
Overall layout is:
<profile>
  <network_drives>
    <network drive id="0" drive_letter="z:" drive_path="\\servername\share">
<network drive id="1" drive_letter="z:" drive_path="\\servername\share">
     there are a few more network drive elements exactly the same but different mappings
     </network_drives>
    <recent_documents>
     <recent_document id="2" document_name="blah" document_path="c:\desktop\folder1">
        <recent_document id="3" document_name="blah2.doc" document_path="c:\desktop\folder1">
      there are many recent documents if it matters all the id #'s are unique starting from 0 in network drives
     </recent_documents>
</profile>

Since there are few network drives I was trying to use
 set node = xmlDoc.selectSingleNode("\\network_drives\network_drive")
 but I got stuck because I did not know how to differentiate between the nodes within <network_drives> because they are all named network_drive but have different attributes. Also the command line spit out object required : 'node'

For the recent documents I basically want to do the same thing but I figure a loop would be better because there are far more entries. All I really care about is analyzing the path in the document and checking it against a variable.

Can anyone guide me in the correct way of using select single node and / or a loop to go through my xml document and get me the information i need?

Thanks in advance,
barry

0
Comment
Question by:barryk2
  • 3
4 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 11999061
Well, you can use selectSingleNode on any node, so if you find a particular node you're interested in, you can use it for the basis of subsequent searches.  To refine the XPath for a particular network_drive node, use a predicate:

set node = xmlDoc.selectSingleNode("\\network_drives\network_drive[@drive_letter = 'z']")

or even drive_path="\\servername\share"

set node = xmlDoc.selectSingleNode("\\network_drives\network_drive[contains(@drive_path, 'sharedFolderName')]")

to use a variable in it:

folderName = "myFolder"

set node = xmlDoc.selectSingleNode("\\network_drives\network_drive[contains(@drive_path, '" & folderName & "')]")

Regards,
Mike Sharp
0
 

Author Comment

by:barryk2
ID: 11999106
when i past your top code I get an error:

msxml4.dll : Unexpected character in query stirng

-->\<--\network_drives\netowrk_drive[@drive_letter = 'z' ]

also to verify node got set could i just print it like this: WScript.Echo node.text?
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 500 total points
ID: 11999546
Oops.  I copied your code, and modified it to show the predicate, but didn't notice the backslashes.  They need to be "/" not "\"

Regards,
Mike Sharp
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 11999560
By the way, if you need to do something with a number of nodes, and they're all identified by the same XPath expression, you can use selectNodes() which returns a nodelist you can iterate over.

Regards,
Mike Sharp
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Extract data from xml in c# 8 60
Mongodb hierarchy 2 55
c#, split 12 81
XML XSL Choose example 3 25
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 …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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