mikrom (Programmer) |
23 Jul 12 5:01 |
Here is an simple example how to do it in VBscript
workstation_parse.vbs
CODEset xml_doc = CreateObject("Microsoft.XMLDOM")
xml_doc.load("workstation.xml")
'parse Workstation attributes
set node = xml_doc.selectSingleNode("/Workstation")
attr_id = "Number"
attr_val = node.getAttribute(attr_id)
wscript.echo("Workstation " & attr_id & "= " & attr_val)
attr_id = "UserDef1"
attr_val = node.getAttribute(attr_id)
wscript.echo("Workstation " & attr_id & "= " & attr_val)
attr_id = "UserDef2"
attr_val = node.getAttribute(attr_id)
wscript.echo("Workstation " & attr_id & "= " & attr_val)
'parse Computer Name and Model
set node = xml_doc.selectSingleNode("/Workstation/Hardware/Computer/Name")
wscript.echo("Computer Name" & "= " & node.Text)
set node = xml_doc.selectSingleNode("/Workstation/Hardware/Computer/Model")
wscript.echo("Computer Model" & "= " & node.Text)
'parse CPU Speed and Model
set node = xml_doc.selectSingleNode("/Workstation/Hardware/CPU/Speed")
wscript.echo("CPU Speed" & "= " & node.Text)
set node = xml_doc.selectSingleNode("/Workstation/Hardware/CPU/Model")
wscript.echo("CPU Model" & "= " & node.Text)
'parse all drives
wscript.echo("Drives:")
set drives = xml_doc.getElementsByTagName("Drive")
for each drive in drives
for each drive_data in drive.ChildNodes
select case drive_data.NodeName
case "Name"
drive_name = drive_data.Text
case "Description"
drive_description = drive_data.Text
case "Capacity"
drive_capacity = drive_data.Text
case "Free"
drive_free = drive_data.Text
end select
next
'print drive data
if drive_name <> "A:" then
if drive_Description = "" then
drive_info = " Name " & drive_name & _
", Capacity: " & drive_capacity & _
", Free: " & drive_free
else
drive_info = " Name " & drive_name & _
", Description: " & drive_description
end if
wscript.echo(drive_info)
end if
next
'at end release XMLDOM object from memory
set xml_doc = nothing
Output:
CODEC:\_mikrom\Work>cscript /NoLogo workstation_parse.vbs
Workstation Number= 80033
Workstation UserDef1= Skq34
Workstation UserDef2= 89098
Computer Name= SPKCDC1A84
Computer Model= ADRADCPI
CPU Speed= 2400
CPU Model= Awardacpi
Drives:
Name C:, Capacity: 99999, Free: 8888888
Name D:, Capacity: 55555555, Free: 4444444
Name F:, Description: DVD_2345 |
|