Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading XML with VBS?

Status
Not open for further replies.

Smithsco

Technical User
Mar 30, 2003
89
AU
Hi,

I'm trying to find a FAQ or tutorial on read XML files with VBS. Can anyone help?
 
thanks for that.

I can now jump from tag to tag, but is there a way to read the file line by line like you can with a standard text file?

 
Smithsco,

I doubt reading line by line has much generic significance for an xml. So the first idea come through is to do it fso?

- tsuji
 
You can read line for line with the FileSystemObject as suggested by tsuji, but I can think of absolutely no reason to need to do so for an XML. Post the specifics of your problem with any code that you have so far and I'm sure we can work out an efficient solution for you.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
OK I have this code here:

set ofso = createobject("scripting.filesystemobject")
set nfile = ofso.createtextfile("c:\a\bb.txt")
Set xmldoc = CreateObject( "Microsoft.XMLDOM" )
xmldoc.Load("C:\a\bex00032.xml")
set nodelist = xmldoc.getElementsByTagName("machine_name")
for each node in nodelist
nfile.writeline node.text
set node = nothing
next
set xmldoc = nothing

and here is an extract from the XML file
- <machine>
<machine_name>XXXXXXXX</machine_name>
<info>Network control connection established </info>
<info>Network data connection is established </info>
- <set>
<set_resource_name>\\XXXXXXXX\C:</set_resource_name>
<tape_name>Family Name: "Media created"</tape_name>
- <volume>
<display_volume>Backup of "\\XXXXXXXX\C:"</display_volume>
</volume>
<description>Backup set #1 "Backup 0005"</description>
<backup_type>Backup Type: FULL</backup_type>
<start_time>Backup started </start_time>
<end_time>Backup completed </end_time>
- <summary>
<misc>Backed up 30426 files in 1158 directories.</misc>
<new_processed_bytes>Processed 2,413,927,258 bytes in 34 minutes and 58 seconds.</new_processed_bytes>
<vlm_hist_rateformat2>Throughput rate: 65.8 MB/min</vlm_hist_rateformat2>
</summary>
<filler>----------------------------------------------------------------------</filler>
</set>




As you can imagine there is a set of the above for each drive on each server, so I would like a way to either dumb the lot to a standard text file or a way to grab specific data from each set. As you may see from the code to start with it searches through the entire document at once.. not really what I'm after.
 
Smithsco,

Try this see if the elements retrieved are suitable for writing to textfile as such.
Code:
set xmldoc=createobject("msxml2.domdocument") 
xmldoc.load "C:\a\bex00032.xml"
xmldoc.async=false
set machine = xmldoc.documentelement
for each onode in machine.childnodes
	wscript.echo onode.nodename & "=" & onode.text
next
set xmldoc=nothing
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top