Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


extract Data from XML file

extract Data from XML file

extract Data from XML file

I would like help on the best way to extract the highlighted data from the XML file below this data will then be loaded in a Database any language is fine I am tryihg in C# or PHP, The info is in RED
Any help will be greatly appreciated.... Thanks

<?xml version="1.0" encoding="ISO-8859-1"?>
<Workstation Number="80033" CompType="0" Type="baseline" UserDef1="Skq34" UserDef2="89098" Userdef3="76" Comment="This is a test" >
<ServiceTag />
<BiosName>AT/AT Comp</BiosName>





<Description> DVD_2345</Description>


RE: extract Data from XML file

Here is an simple example how to do it in VBscript


set xml_doc = CreateObject("Microsoft.XMLDOM")


'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

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
  'print drive data
  if drive_name <> "A:" then
    if drive_Description  = "" then
      drive_info = "  Name " & drive_name & _
                   ", Capacity: " & drive_capacity & _
                   ", Free: " & drive_free
      drive_info = "  Name " & drive_name & _
                   ", Description: " & drive_description
    end if
  end if  

'at end release XMLDOM object from memory
set xml_doc = nothing 


C:\_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
  Name C:, Capacity: 99999, Free: 8888888
  Name D:, Capacity: 55555555, Free: 4444444
  Name F:, Description: DVD_2345 

RE: extract Data from XML file


Thanks you so much for the example thats a GREAT example, just what I needed!!!!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close