Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Solved... Help reading XML files using VBScript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,37404
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Solved... Help reading XML files using VBScript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Solved... Help reading XML files using VBScript - 8/30/2006 6:04:41 AM   
  NsOnLn

 

Posts: 1
Score: 0
Joined: 8/30/2006
Status: offline
I figured it out! :)

I am trying to look in a folder for the daily log files from backup exec and using vbscript gather data from it to insert into a database. Here is a sample of the XML file:

<?xml version="1.0" encoding="UTF-16"?>
<joblog><job_log_version version="2.0"/>
   <header><filler>======================================================================
</filler><server>Job server: !@#$%^
</server><name>Job name: !@#$%^\backup-Backup Policy-Daily Backup
</name><start_time>Job started: Thursday, August 24, 2006 at 9:37:49 PM
</start_time><type>Job type: Backup
</type><log_name>Job Log: BEX_!@#$%^_06618.xml
</log_name><filler>======================================================================
</filler></header><media_mount_date>
Drive and media mount requested: 8/24/2006 9:37:49 PM
</media_mount_date><media_drive_and_media_info><media_mount_date>
Drive and media information from media mount: 8/24/2006 9:37:49 PM
</media_mount_date><robotic_library_name>Robotic Library Name: HP StorageWorks MSL5052
</robotic_library_name><drive_name>Drive Name: HP Drive 1
</drive_name><slot>Slot: 21
</slot><media_label>Media Label: 000021D
</media_label><media_guid>Media GUID: {e139e313-9985-417f-ae95-fbe039c43e01}
</media_guid><media_overwrite_date>Overwrite Protected Until: 8/31/2006 9:00:44 PM
</media_overwrite_date><media_append_date>Appendable Until: 8/31/2006 9:00:44 PM
</media_append_date><media_set_target>Targeted Media Set Name: Daily Media Set
</media_set_target></media_drive_and_media_info><backup><filler>======================================================================
</filler><title>Job Operation - Backup
</title><append_or_overwrite>Media operation - append.
</append_or_overwrite><compression>Hardware compression enabled.
</compression><verify_option>WARNING: The option 'Verify after backup completes' was not selected.
Performing a verify operation to make sure that media can be read after the backup has completed is recommended.
</verify_option><filler>======================================================================
</filler><machine><machine_name>!@#$%^</machine_name><w2k_backup_no_aa_warning>WARNING: Media servers cannot completely protect remote
Windows-based servers or workstations unless the Backup
Exec Remote Agent is installed
and running on each remote Windows-based server or
workstation to be protected. Data loss can occur if the
Remote Agent is not running
while backing up remote Windows-based computers.

Please refer to the documentation or online help for more information.
</w2k_backup_no_aa_warning><OperationErrors Type="snapshot_init_failure">AOFO: Initialization failure on: "\\!@#$%^\BACKUP". Advanced Open File Option used: No.
</OperationErrors><OperationErrors Type="snapshot_init_failure">Remote Agent not detected on !@#$%^.
</OperationErrors><NewLine></NewLine><OperationErrors Type="error">Access is denied to Remote Agent.  Check the login account for the specified device.
</OperationErrors></machine></backup><footer><filler>======================================================================
</filler><end_time>Job ended: Thursday, August 24, 2006 at 9:39:06 PM
</end_time><engine_completion_status>Job completion status: Failed
</engine_completion_status><filler>======================================================================
</filler><completeStatus>6</completeStatus><errorDescription>Final error: 0xe000fe29 - Authentication failed on connection to the server. Make sure that the user account has the appropriate permissions and that the password was typed correctly.
</errorDescription><errorCategory>Final error category: Security Errors</errorCategory><umiOriginator>79</umiOriginator><justErrorCode>-536805847</justErrorCode></footer></joblog>


Here is my vbscript:

Dim server, filepath
Dim fso,fold,fil,XMLDoc

Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.GetFolder("C:\Temp")

For each fil in fold.files
   If DateDiff("d",Now,fil.DateCreated) = 0 Then
         Set xmlDoc = CreateObject("Msxml2.DOMDocument")
         'MsgBox (Chr(34) & fil & Chr(34))
        'xmlDoc.load(Chr(34) & fil & Chr(34))

       fil = fold & "\" & fil.name
        xmlDoc.load(fil)

   
        Set ElemList = xmlDoc.getElementsByTagName("machine_name")
        server = ElemList.item(0).Text
        Wscript.Echo server

        Set ElemList = xmlDoc.getElementsByTagName("server")
        jserver = Replace(ElemList.item(0).Text,"Job server:","")
        Wscript.Echo jserver

        Set ElemList = xmlDoc.getElementsByTagName("name")
        jname = Replace(ElemList.item(0).Text,"Job name:","")
        Wscript.Echo jname
        
        Set ElemList = xmlDoc.getElementsByTagName("start_time")
        start_time = Replace(ElemList.item(0).Text,"Job started:","")
        Wscript.Echo start_time
        
        Set ElemList = xmlDoc.getElementsByTagName("slot")
        slot = Replace(ElemList.item(0).Text,"Slot:","")
        Wscript.Echo slot
        
        Set ElemList = xmlDoc.getElementsByTagName("media_label")
        mlabel = Replace(ElemList.item(0).Text,"Media Label:","")
        Wscript.Echo mlabel
        
        Set ElemList = xmlDoc.getElementsByTagName("end_time")
        end_time = Replace(ElemList.item(0).Text,"Job ended:","")
        Wscript.Echo end_time
        
        Set ElemList = xmlDoc.getElementsByTagName("engine_completion_status")
        engine_completion_status = Replace(ElemList.item(0).Text,"Job completion status:","")
        Wscript.Echo engine_completion_status
        
        Set ElemList = xmlDoc.getElementsByTagName("errorDescription")
        ferrors = Replace(ElemList.item(0).Text,"Final error:","")
        Wscript.Echo ferrors
   end If
Next


When I MsgBox the file name it shows that it has detected the correct file. But I get this error message:

G:\openaudit\scripts\backupexeclognew.vbs(40, 3) Microsoft VBScript runtime error: Object required: 'ElemList.item(...)'


I am under the gun to get this working ASAP so any help would be greatly appreciated. Thanks

< Message edited by NsOnLn -- 8/30/2006 6:44:18 AM >
 
 
Post #: 1
 
 RE: Solved... Help reading XML files using VBScript - 11/29/2006 7:14:47 PM   
  TNO


Posts: 1399
Score: 16
Joined: 12/18/2004
From: thenewobjective.com
Status: online
Instead of doing this:

ElemList = xmlDoc.getElementsByTagName("blah")

you should try this:

ElemList = xmlDoc.selectSingleNode("/joblog/backup/machine/machine_name").item(0).text

Beware, if you are not 100% certain that this element will always be there I suggest testing the result before using it.

_____________________________

To iterate is human, to recurse divine. -- L. Peter Deutsch

(in reply to NsOnLn)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Solved... Help reading XML files using VBScript Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts