flash-gordon
Goto Top

String in xml Datei finden und die 7 Zeichen danach an Variable übergeben

Hallo zusammen! Ich habe ein Problemchen welches ich bisher leider nicht mit Hifle des Forums lösen konnte! face-sad

Also: ich habe die XML Datei "c:\temp\test.xml"

In dieser Datei möchte ich folgenden String finden: "</drive_name><slot>"

In Gänze steht in dieser Zeile: "</drive_name><slot>Slot: 8"

Wobei ich das "Slot: 8" an eine Variable zur Weiterverarbeitung übergeben möchte.

Habe schon diverse Lösungsansätze getestet....ohne Erfolg! face-sad

Ich steh wirklich auf dem Schlauch!

Kann mir jemand helfen?

Gruß Flash

Content-ID: 130918

Url: https://administrator.de/forum/string-in-xml-datei-finden-und-die-7-zeichen-danach-an-variable-uebergeben-130918.html

Ausgedruckt am: 24.12.2024 um 13:12 Uhr

bastla
bastla 04.12.2009 um 00:18:49 Uhr
Goto Top
Hallo flash-gordon!

Der folgende Batch sollte auch für mehrere entsprechende Einträge die gewünschten 7 Zeichen (es wird vorausgesetzt, dass diese tatsächlich vorhanden sind) zurück- (bzw aus-) geben:
@echo off & setlocal
set "Datei=C:\Temp\test.xml"  
set "Such=</drive_name><slot>"  
set "ZAnzahl=7"  

set GT=%temp%\GetText.vbs
>%GT%  echo Z=%ZAnzahl%:S="%Such%":L=Len(S):T=CreateObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments(0)).ReadAll  
>>%GT% echo P=1:F=InStr(P,T,"%Such%"):Do While F^>0:P=F+L:WScript.Echo Mid(T,P,Z):F=InStr(P,T,"%Such%"):Loop  

for /f "delims=" %%i in ('cscript //nologo %GT% "%Datei%"') do echo %%i  
Je nach tatsächlicher Anzahl der "Slot:"-Einträge bzw gewünschter Weiterverarbeitung könnte Zeile 10 zB so umformuliert werden:
for /f "delims=" %%i in ('cscript //nologo %GT% "%Datei%"') do set "Slot=%%i"
Grüße
bastla
flash-gordon
flash-gordon 04.12.2009 um 00:34:49 Uhr
Goto Top
Hallo bastla,

wenn ich dein Script teste und am Ende "echo %%i" ausgeben lasse bekomme ich:

"%i"

sonst nichts! face-sad
bastla
bastla 04.12.2009 um 00:47:05 Uhr
Goto Top
Hallo flash-gordon!

Dass die Ausgabe unter Anführungszeichen erfolgen würde, kann ich mir überhaupt nicht vorstellen ...
Kannst Du ein Beispiel Deiner "xml"-Datei und den konkret verwendeten Script-Code posten (jeweils als formatiert)?

[Edit] Sollte für die "xml"-Datei Unicode verwendet werden, müsste die Zeile 7 geändert werden:
>%GT%  echo Z=%ZAnzahl%:S="%Such%":L=Len(S):T=CreateObject("Scripting.FileSystemObject").OpenTextFile(WScript.Arguments(0),1,True).ReadAll 
[/Edit]

Grüße
bastla
flash-gordon
flash-gordon 04.12.2009 um 00:50:58 Uhr
Goto Top
del C:\prTemp\GetText.vbs



@echo on & setlocal
set "Datei=C:\Temp\CopyofBEX_GERMFI01_07182.xml"  
set "Such=</drive_name><slot>"  
set "ZAnzahl=7"  

set GT=%temp%\GetText.vbs
>%GT%  echo Z=%ZAnzahl%:S="%Such%":L=Len(S):T=CreateObject("Scripting.FileSystemObject").OpenTextFile  

(WScript.Arguments(0)).ReadAll
>>%GT% echo P=1:F=InStr(P,T,"%Such%"):Do While F^>0:P=F+L:WScript.Echo Mid(T,P,Z):F=InStr(P,T,"%Such%"):Loop  

for /f "delims=" %%i in ('cscript //nologo %GT% "%Datei%"') do echo "%%i"  

Das ist der Code den ich verwendet habe!

Dies hier ein Auszug aus der xml, in der nur eine Zeile den gesuchten String aufweist:
</setcopy_destination_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:08:10 AM
</media_mount_date><robotic_library_name>Robotic Library Name: DELL 1
</robotic_library_name><drive_name>Drive Name: IBM 1
</drive_name><slot>Slot: 8
</slot><media_label>Media Label: 000001L3
</media_label><media_guid>Media GUID: {a41b136b-b43e-4104-a184-aa7ff706d175}
</media_guid><media_overwrite_date>Overwrite Protected Until: 02/12/2009 1:35:08 AM
</media_overwrite_date><media_append_date>Appendable Until: 28/11/2009 1:31:12 AM
</media_append_date><media_set_target>Targeted Media Set Name: Tape
</media_set_target></media_drive_and_media_info><media_mount_date>

Gruß
flash


pause
bastla
bastla 04.12.2009 um 00:55:26 Uhr
Goto Top
Hallo flash-gordon!

Die Zeilen 11 und 13 gehören zusammen ...

Grüße
bastla
flash-gordon
flash-gordon 04.12.2009 um 01:04:37 Uhr
Goto Top
del C:\Temp\GetText.vbs



@echo on & setlocal
set "Datei=C:\Temp\CopyofBEX_GERMFI01_07182.xml"  
set "Such=</drive_name><slot>"  
set "ZAnzahl=7"  

set GT=%temp%\GetText.vbs
>%GT%  echo Z=%ZAnzahl%:S="%Such%":L=Len(S):T=CreateObject("Scripting.FileSystemObject").OpenTextFile (WScript.Arguments(0)).ReadAll  
>>%GT% echo P=1:F=InStr(P,T,"%Such%"):Do While F^>0:P=F+L:WScript.Echo Mid(T,P,Z):F=InStr(P,T,"%Such%"):Loop  

for /f "delims=" %%i in ('cscript //nologo %GT% "%Datei%"') do echo "%%i"  

Damit bekomme ich trotzdem kein Ergebnis!
bastla
bastla 04.12.2009 um 01:12:52 Uhr
Goto Top
Hallo flash-gordon!

Beim Test mit Deinen beiden geposteten Dateien erhalte ich als Ergebnis wie gewünscht
"Slot: 8"
Könnte es sein, dass die "xml"-Datei ev tatsächlich nicht im ASCII- bzw ANSI-Format vorliegt? In diesem Fall siehe mein "[Edit]" oben ...

Grüße
bastla

P.S.: Die Zeile
del C:\Temp\GetText.vbs
ist nicht erforderlich, da das VBScript ohnehin bei jedem Durchlauf neu erstellt wird (siehe Zeile 11 mit einem einzelnen ">") - selbst wenn Dein %temp%-Pfad tatsächlich auf "C:\Temp" zeigen sollte ...
flash-gordon
flash-gordon 04.12.2009 um 17:41:34 Uhr
Goto Top
Scheint in der Tat an dem Format der XML zu liegen.
Hast du eine Ahnung wie ich das lösen kann?
Vielleicht mit msxsl.exe?
bastla
bastla 04.12.2009 um 18:22:55 Uhr
Goto Top
Hallo flash-gordon!

Ohne eine Originaldatei (die oben angesprochene Variante "Unicode" war's ja offensichtlich nicht, sonst hätte es mit der geänderten Scriptzeile geklappt) gesehen zu haben, kann ich leider nicht wirklich eine Empfehlung abgeben ...

Grüße
bastla
flash-gordon
flash-gordon 04.12.2009 um 18:29:01 Uhr
Goto Top
Zitat von @bastla:
Hallo flash-gordon!

Ohne eine Originaldatei (die oben angesprochene Variante "Unicode" war's ja offensichtlich nicht, sonst hätte
es mit der geänderten Scriptzeile geklappt) gesehen zu haben, kann ich leider nicht wirklich eine Empfehlung abgeben ...

Grüße
bastla

Ich lade später einmal eine ins Netz und schicke dir eine PN, wenn das ok für dich ist.
dank vorab.
flash-gordon
flash-gordon 04.12.2009 um 21:55:47 Uhr
Goto Top
Hab es noch net geschafft die Datei ins Netz zu laden.
Hier aber die erste Zeile der XML:

<?xml version="1.0" encoding="UTF-16"?> 

gruß
Flash
flash-gordon
flash-gordon 04.12.2009 um 22:30:58 Uhr
Goto Top
Hier noch einla die ganze XML als code:

<joblog><job_log_version version="2.0"/><header><filler>======================================================================  
</filler><server>Job server: GERMFI01
</server><name>Job name: Duplicate Full Backup
</name><start_time>Job started: Wednesday, November 25, 2009 at 5:07:17 AM
</start_time><type>Job type: Duplicate
</type><log_name>Job Log: BEX_GERMFI01_07182.xml
</log_name><filler>======================================================================
</filler></header><media_mount_date>
Drive and media mount requested: 25/11/2009 5:07:17 AM
</media_mount_date><media_drive_and_media_info><setcopy_destination_device>
Destination Drive and Media
</setcopy_destination_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:08:10 AM
</media_mount_date><robotic_library_name>Robotic Library Name: DELL 1
</robotic_library_name><drive_name>Drive Name: IBM 1
</drive_name><slot>Slot: 8
</slot><media_label>Media Label: 000001L3
</media_label><media_guid>Media GUID: {a41b136b-b43e-4104-a184-aa7ff706d175}
</media_guid><media_overwrite_date>Overwrite Protected Until: 02/12/2009 1:35:08 AM
</media_overwrite_date><media_append_date>Appendable Until: 28/11/2009 1:31:12 AM
</media_append_date><media_set_target>Targeted Media Set Name: Tape
</media_set_target></media_drive_and_media_info><media_mount_date>
Drive and media mount requested: 25/11/2009 5:08:10 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:08:10 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000280
</media_label><media_guid>Media GUID: {ae665647-04d1-4cf7-9103-fb0be000f58f}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 2:53:03 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><setcopy><filler>======================================================================
</filler><title>Job Operation - Duplicate
</title><append_or_overwrite>Media operation - append.
</append_or_overwrite><compression>Compression Type: Hardware [if available, otherwise none]
</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><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #1: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "C: system"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 2:05 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #1: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>system</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #16: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 5:08:50 AM.
</start_time><end_time>Duplicate completed on 25/11/2009 at 5:10:56 AM.
</end_time><summary><misc>Backed up 29756 files in 3515 directories.
</misc><new_processed_bytes>Processed 3,577,462,104 bytes in  2 minutes and  6 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 1625 MB/min
</vlm_hist_rateformat2></summary><filler>----------------------------------------------------------------------
</filler></set><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #2: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "E: binaries"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 2:26 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #1: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>binaries</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #17: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 5:10:56 AM.
</start_time><end_time>Duplicate completed on 25/11/2009 at 5:12:39 AM.
</end_time><summary><misc>Backed up 92455 files in 5181 directories.
</misc><new_processed_bytes>Processed 4,040,145,327 bytes in  1 minute and  43 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 2244 MB/min
</vlm_hist_rateformat2></summary><filler>----------------------------------------------------------------------
</filler></set><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #3: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "F: log"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 2:37 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #1: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>log</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #18: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 5:12:39 AM.
</start_time><end_time>Duplicate completed on 25/11/2009 at 5:12:47 AM.
</end_time><summary><misc>Backed up 1580 files in 803 directories.
</misc><new_processed_bytes>Processed 155224266 bytes in  8 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 1110 MB/min
</vlm_hist_rateformat2></summary><filler>----------------------------------------------------------------------
</filler></set><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #4: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "G: data"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 2:37 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #1: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>data</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #19: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 5:12:47 AM.
</start_time><end_time>Duplicate completed on 25/11/2009 at 5:12:57 AM.
</end_time><summary><misc>Backed up 4297 files in 560 directories.
</misc><new_processed_bytes>Processed 251214971 bytes in  10 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 1437 MB/min
</vlm_hist_rateformat2></summary><filler>----------------------------------------------------------------------
</filler></set><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #5: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "H: user"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 2:38 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #1: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>user</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #20: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 5:12:57 AM.
</start_time><media_mount_date>
Drive and media mount requested: 25/11/2009 5:18:57 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:18:58 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000281
</media_label><media_guid>Media GUID: {82351409-7aa6-4bd9-bee4-931c1cfd7f61}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 3:19:05 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><media_mount_date>
Drive and media mount requested: 25/11/2009 5:28:26 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:28:27 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000282
</media_label><media_guid>Media GUID: {6fd19247-7b9c-40a3-aacf-171d03b59efc}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 4:09:08 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><media_mount_date>
Drive and media mount requested: 25/11/2009 5:37:48 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:37:49 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000283
</media_label><media_guid>Media GUID: {00b15b11-6da6-438a-bae7-6f8b3d1a0343}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 4:29:12 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><media_mount_date>
Drive and media mount requested: 25/11/2009 5:47:22 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:47:23 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000284
</media_label><media_guid>Media GUID: {2afca30b-1e0e-4cca-9e72-ee81bbca696c}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 4:49:14 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><media_mount_date>
Drive and media mount requested: 25/11/2009 5:56:41 AM
</media_mount_date><media_drive_and_media_info><setcopy_source_device>
Source Drive and Media
</setcopy_source_device><media_mount_date>
Drive and media information from media mount: 25/11/2009 5:56:42 AM
</media_mount_date><drive_name>Drive Name: Full
</drive_name><media_label>Media Label: B2D000285
</media_label><media_guid>Media GUID: {12bed942-f910-414c-a23b-1795b9ef9ada}
</media_guid><media_overwrite_date>Overwrite Protected Until: 25/11/2009 5:05:09 PM
</media_overwrite_date><media_append_date>Appendable Until: 31/12/9999 1:00:00 AM
</media_append_date></media_drive_and_media_info><end_time>Duplicate completed on 25/11/2009 at 6:00:07 AM.
</end_time><summary><misc>Backed up 334953 files in 44652 directories.
</misc><new_processed_bytes>Processed 106679417181 bytes in  47 minutes and  5 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 2161 MB/min
</vlm_hist_rateformat2></summary><filler>----------------------------------------------------------------------
</filler></set><set><setcopy_set><setcopy_source_set>
Source Set
</setcopy_source_set><setcopy_backup_set>
Backup set #6: "FULL Backup Office Template" 
</setcopy_backup_set><display_volume>Backup of "System?State System?State"  
</display_volume><setcopy_backup_performed>Backup performed on 25/11/2009 at 4:59 AM
</setcopy_backup_performed><setcopy_storage_media>Storage media #6: "Media created 25/11/2009 2:00:01 AM" 
</setcopy_storage_media></setcopy_set><set_resource_name>System?State</set_resource_name><setcopy_set><setcopy_destination_set>
Destination Set
</setcopy_destination_set><setcopy_backup_set>
Backup set #21: "Duplicate Full Backup Office" 
</setcopy_backup_set><setcopy_storage_media>Storage media #1: "Media created 21/11/2009 1:30:01 AM" 
</setcopy_storage_media></setcopy_set><start_time>Duplicate started on 25/11/2009 at 6:00:08 AM.
</start_time><shadow_copy_component></shadow_copy_component><shadow_copy_component></shadow_copy_component><shadow_copy_component></shadow_copy_component><shadow_copy_component></shadow_copy_component><shadow_copy_component></shadow_copy_component><end_time>Duplicate completed on 25/11/2009 at 6:00:41 AM.
</end_time><summary><misc>Backed up 0 files in 1 directory.
</misc><new_processed_bytes>Processed 1,168,573,258 bytes in  33 seconds.
</new_processed_bytes><vlm_hist_rateformat2>Throughput rate: 2026 MB/min
</vlm_hist_rateformat2></summary><empty_set_warning>This backup set may not contain any data.
</empty_set_warning><filler>----------------------------------------------------------------------
</filler></set></setcopy><footer><filler>======================================================================
</filler><end_time>Job ended: Wednesday, November 25, 2009 at 6:01:41 AM
</end_time><engine_completion_status>Job completion status: Successful
</engine_completion_status><filler>======================================================================
</filler><completeStatus>19</completeStatus></footer></joblog>
bastla
bastla 05.12.2009 um 09:06:44 Uhr
Goto Top
Hallo flash-gordon!

Du könntest vorweg noch Folgendes versuchen: Ersetzte im Batch die Zeile
set "Datei=C:\Temp\CopyofBEX_GERMFI01_07182.xml"
durch
set "Datei=%Temp%\GERMFI01.txt"
type "C:\Temp\CopyofBEX_GERMFI01_07182.xml" > "%Datei%"
Grüße
bastla
flash-gordon
flash-gordon 05.12.2009 um 12:44:25 Uhr
Goto Top
Zitat von @bastla:
Hallo flash-gordon!

Du könntest vorweg noch Folgendes versuchen: Ersetzte im Batch die Zeile
set "Datei=C:\Temp\CopyofBEX_GERMFI01_07182.xml"
> 
durch
set "Datei=%Temp%\GERMFI01.txt"
> type "C:\Temp\CopyofBEX_GERMFI01_07182.xml" > "%Datei%"
> 
Grüße
bastla

LÄUFT!!!!

1000 Dank!