Batch Script File to Extract XML Tag Data

Kamion

New Member
Need help extracting Data from xml and passing it to Batch File Variables...i cant seem to get the data needed and be able to pass it to batch variable.i need to extract "AH0417" from the TAGID.... Catch 22- this file changes the TAGID / PHASEID / BOXIDso they are rarely the same... i can extract one specific file if i change delims to \[code\]for /f "tokens=7,18-21* delims=^<![CDT[^>]] " %%a in ('find /I /N "<PHASEID>"^<Config.xml') do (set a=%%a)echo %a%\[/code\]thats where i am now with all the different methods of delims and or tokens, if i use skip=3 it causes unexpected ]any help would be outstanding, i've been working this all week and posted online for help, still no replies...i dont know if this is just going to be that difficult or impossible, but i know its possible, i need the right set of eyes looking at this lol. thanks in advance for any help...\[code\] <?xml version="1.0" encoding="UTF-16"?>-<root>-<CONFIG>-<TAGID><![CDATA[AH0417]]></TAGID>-<DATETIMESTAMP><![CDATA[9/18/2012 4:59:08 PM]]></DATETIMESTAMP>-<SYSTYPE><![CDATA[PTWS]]></SYSTYPE>-<PHASEID><![CDATA[WJFKB02229001]]></PHASEID>-<BOXID><![CDATA[D]]></BOXID></CONFIG></root>\[/code\]i have used many different combinations with tokens and delims but i either get blank %PhaseID% or i get the number "2" as a result instead of actual data.this is what i am trying to do...\[code\]REM ***************************************(PTLS)******************************************************** :PTLSsetup sET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTLS\DATA\XML rem Extract XML to Batch rem for /f "skip=3 tokens=* delims=[" %%G IN (C:\Ullsa\phase\ptls\data\xml\Config.xml) Do ( rem Set Serial=%%G rem Set PhaseID=%%H rem Set BoxID=%%I rem ) rem echo %serial% rem echo %PhaseID% rem echo %BoxID%\[/code\]this is the full script.....\[code\]mode con:cols=70 lines=25rem Created by (ROBERT)color 0cfor /f "tokens=2-4 delims=/ " %%a in ('date /t') do set year=%%cfor /f "tokens=2-4 delims=/ " %%a in ('date /t') do set month=%%afor /f "tokens=2-4 delims=/ " %%a in ('date /t') do set day=%%bset today=%day%-%month%-%year%echo %today%rem **************************(LOG CREATION)************************************************md c:\zMigrate\Backupset currentd=C:\zMigrate\Backupping -n 6 127.0.0.1 >nulCLSecho.set D=%date% %time%set T=%time%echo ****************************************** >>%currentd%\%today%.TXTecho %Date% ---------------------^> Log Created on %computername% >>%currentd%\%today%.TXTecho ****************************************** >>%currentd%\%today%.TXTecho LOG CREATED IN %currentd%\%today%.TXTecho LOG CREATED FROM %currentd% >>%currentd%\%today%.TXTecho ****************************************** >>%currentd%\%today%.TXTclsrem ******************************(MENU)****************************************************:Menuecho *******************IF EXIST "C:\ULLSA\PHASE\PTLS" ECHO PTLS IS INSTALLEDIF ERRORLEVEL 1 ECHO PTLS NOT INSTALLEDIF EXIST "C:\ULLSA\PHASE\PTWS" ECHO PTWS IS INSTALLEDIF ERRORLEVEL 1 ECHO PTWS NOT INSTALLEDecho *******************IF EXIST "C:\ULLSA\PHASE\PTLS" ECHO %T% PTLS IS INSTALLED >>%currentd%\%today%.TXTIF ERRORLEVEL 1 ECHO %T% PTLS NOT INSTALLED >>%currentd%\%today%.TXTIF EXIST "C:\ULLSA\PHASE\PTWS" ECHO %T% PTWS IS INSTALLED >>%currentd%\%today%.TXTIF ERRORLEVEL 1 ECHO %T% PTWS NOT INSTALLED >>%currentd%\%today%.TXTecho.echo.echo.echo.echo.echo WHAT TYPE WORKSTATION IS THIS?echo.echo *NOTE* THIS UTILITY WILL PHASE MIGRATION FILES!!!echo.echo.ECHO 1: PTLS (Phase Team Leader Station)echo.ECHO 2: PTWS (Phase Team Workers Station)echo.ECHO 0: Leave ProgramECHO.SET /p choice=Enter a number [0,1,2]: if /i [%choice%]==[0] endlocal&goto end if [%choice%]==[] goto Menu if [%choice%]==[1] goto PTLS if [%choice%]==[2] goto PTWS ECHO Unrecognized entry. Please try again. goto MenuREM ***************************************(TYPE CHECK)**************************************************:PTLSclsECHO *************************echo ***Starting PTLS Check***ECHO *************************echo %T% ***Starting PTLS Check*** >>%currentd%\%today%.TXTPING -n 3 127.0.0.1>nulCLSset PTLSDATA="http://stackoverflow.com/questions/12545488/C:/ULLSA/PHASE/PTLS/DATA/XML"if exist %ptlsdata%\config.xml goto PTLSsetupif errorlevel 1 goto PTLSFail:PTLSFAILclsecho ********************************************************echo **PTLS XML DOES NOT EXIST, ENSURE PTLS IS INSTALLED...**echo ********************************************************echo %T% **PTLS XML DOES NOT EXIST, ENSURE PTLS IS INSTALLED...** >>%currentd%\%today%.TXTping -n 6 127.0.0.1>nulgoto Menu:PTWSclsECHO *************************echo ***Starting PTWS Check***ECHO *************************echo %T% ***Starting PTWS Check*** >>%currentd%\%today%.TXTPING -n 3 127.0.0.1>nulCLSset PTWSDATA="http://stackoverflow.com/questions/12545488/C:/ULLSA/PHASE/PTwS/DATA/XML"if exist %ptwsdata%\config.xml goto PTWSsetupif errorlevel 1 goto PTWSFail:PTWSFAILclsecho ********************************************************echo **PTWS XML DOES NOT EXIST, ENSURE PTWS IS INSTALLED...**echo ********************************************************echo %T% PTWS XML DOES NOT EXIST, ENSURE PTWS IS INSTALLED. >>%currentd%\%today%.TXTping -n 6 127.0.0.1>nulgoto MenuREM ***************************************(PTLS)********************************************************:PTLSsetupsET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTLS\DATA\XMLrem Extract XML to Batchrem for /f "skip=3 tokens=* delims=[" %%G IN (C:\Ullsa\phase\ptls\data\xml\Config.xml) Do (rem Set Serial=%%Grem Set PhaseID=%%Hrem Set BoxID=%%Irem )rem echo %serial%rem echo %PhaseID%rem echo %BoxID%echo **********************************echo ***Setting up PhaseID and BoxID***echo **********************************echo %T% ***Setting up PhaseID and BoxID*** >>%currentd%\%today%.TXTping -n 4 127.0.0.1>nulCLSrem extract xml data to phaseid and boxidSet PhaseID=PhaseIDSet BoxID=BoxIDset Pbackup=%HOMEDRIVE%\Backup\%PhaseID%set Bbackup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%Set Backup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%ping -n 4 127.0.0.1>nulgoto PTLSBackup:PTLSBackupif exist %backup% goto ptlsxfrif errorlevel 1 goto ptlsmd:ptlsmdMD %backup% >>%currentd%\%today%.TXTecho %T% Creating Phase Folder >>%currentd%\%today%.TXTecho %T% Creating Box Folder >>%currentd%\%today%.TXTecho Creating Destinationping -n 6 127.0.0.1>nulif exist %Bbackup% goto ptlsxfrif errorlevel 1 echo %T% CAN^'T CREATE DESTINATION >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulCLSgoto menu:ptlsxfrecho ****************************echo ***Created Destination***echo ****************************echo %T% ***Created Destination*** >>%currentd%\%today%.TXTPING -n 3 127.0.0.1>nulCLSecho ****************************echo ***Starting PTLS Transfer***echo ****************************echo %T% ***Starting PTLS Transfer*** >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulCLSecho.cacls "%sOURCE%" /T /E >>%currentd%\%today%.TXTcacls "%backup%" /T /E >>%currentd%\%today%.TXTCLSecho Transfering Phase: %phaseID% Box: %BoxID%echo %T% Transfering Phase: %phaseID% Box: %BoxID% >>%currentd%\%today%.TXTxcopy "%sOURCE%\*" "%backup%\" /Y /E /H /V /G >>%currentd%\%today%.TXTCLSECHO Transfer CompleteECHO %T% Transfer Complete >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulEXITREM ***************************************(PTWS)********************************************************:PTWSsetuprem Extract XML to Batchrem place code or cmd to call to vbsecho **********************************echo ***Setting up PhaseID and BoxID***echo **********************************echo %T% ***Setting up PhaseID and BoxID*** >>%currentd%\%today%.TXTping -n 4 127.0.0.1>nulCLSrem extract xml data to phaseid and boxidSet PhaseID=PhaseIDSet BoxID=BoxIDset Pbackup=%HOMEDRIVE%\Backup\%PhaseID%set Bbackup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%Set Backup=%HOMEDRIVE%\Backup\%PhaseID%\%BoxID%sET sOURCE=%HOMEDRIVE%\ULLSA\PHASE\PTWS\DATA\XMLgoto PTWSBackup:PTWSBackupif exist %backup% goto ptWsxfr >>%currentd%\%today%.TXTif errorlevel 1 goto ptWsmd >>%currentd%\%today%.TXT:ptWsmdMD %backup% >>%currentd%\%today%.TXTecho %T% Creating Phase Folder >>%currentd%\%today%.TXTecho %T% Creating Box Folder >>%currentd%\%today%.TXTecho Creating Destinationping -n 6 127.0.0.1>nulif exist %Bbackup% goto ptWsxfrif errorlevel 1 echo %T% CAN^'T CREATE DESTINATION >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulgoto menu:ptWsxfrecho ****************************echo ***Created Destination***echo ****************************echo %T% ***Created Destination*** >>%currentd%\%today%.TXTPING -n 2 127.0.0.1>nulclsecho ****************************echo ***Starting PTWS Transfer***echo ****************************echo %T% ***Starting PTWS Transfer*** >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulCLSecho.cacls "%sOURCE%" /T /E >>%currentd%\%today%.TXTcacls "%backup%" /T /E >>%currentd%\%today%.TXTCLSecho Transfering Phase: %phaseID% Box: %BoxID%echo %T% Transfering Phase: %phaseID% Box: %BoxID% >>%currentd%\%today%.TXTxcopy "%sOURCE%\*" "%backup%\" /Y /E /H /V /G >>%currentd%\%today%.TXTECHO Transfer CompleteECHO %T% Transfer Complete >>%currentd%\%today%.TXTping -n 3 127.0.0.1>nulEXIT\[/code\]
 
Back
Top