edit xml using a bat or cmd file

February 24, 2011 at 05:01:26
Specs: Windows 7
i have a word document that i need to edit a settings thats hidden

so firstly i rename extension to .zip or .rar using cmd line

extract

this gives you the xml contents of the word document

i then rename seetings.xml to settings.txt

i then want to replace a unique filepath with in the settings.txt with a path thats has been made by user input before this process

save rename, repack then rename etc

im having trouble searching the settings.txt and replacing

any ideas

thanks in advance


See More: edit xml using a bat or cmd file

Report •


#1
February 24, 2011 at 11:24:26
for /f "tokens=*" %%j in ('type settings.txt ^| find "value"') do echo %%j

This is in a batchfile, if you want run this at the command prompt replace the double '%%' with a single one.

So:
for /f "tokens=*" %j in ('type settings.txt ^| find "value"') do echo %j

Happy is ONE who says I am an OttoMAN.


Report •

#2
February 24, 2011 at 13:49:39
thanks for answer

are you able to explain the above please - i would like to learn more about tokens so i can understand and utilise more often

thanks again


Report •

#3
February 25, 2011 at 00:38:57
This makes about as much sense as this one:

http://www.computing.net/answers/pr...


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
February 25, 2011 at 04:54:58
Lets start from the beginning

Im trying to set up a project directory and sub folders including copying templates and renaming them

problem - i have is some of the templates have mail merging that get broken upon copying to new structure

solution - is to rename the word document.docx to document.rar extract contents (word documents are made up of xml files) within the settings.xml there is the path for mail merge document. replace this with user input from creating root directory- save - rearchive - rename back to document.docx - file opens with out errors

Project break down

1 - User input the project name and details
2 - setup root directory
3 - create sub folder structure
4 - copy templates
5 - rename templates based on user input from 1
6 - fix mail merge path
7 - open excel master doc to enter data for mail merge

i have step 1 to 5 below works fine but cant get rest of it to work

@echo off
set DIVCODE=
set PROJNUM=
set YEARDIG=
set PRONAME=
SET PROJLOC=
SET FILEANS=
:input_DIVCODE
set /P DIVCODE=Enter Divisional Code: %=%
cls
if "%DIVCODE%"=="" echo No Divisional Code Entered
if "%DIVCODE%"=="" pause
cls
if "%DIVCODE%"=="" goto input_DIVCODE
:input_PROJNUM
set /P PROJNUM=Enter Project Number: %=%
cls
if "%PROJNUM%"=="" echo No Project Number Entered
if "%PROJNUM%"=="" pause
cls
if "%PROJNUM%"=="" goto input_PROJNUM
:input_YEARDIG
set /P YEARDIG=Enter Year (last 2 diggits): %=%
cls
if "%YEARDIG%"=="" echo No Year Entered
if "%YEARDIG%"=="" pause
cls
if "%YEARDIG%"=="" goto input_YEARDIG
:input_PRONAME
set /P PRONAME=Enter Contract Name: %=%
cls
if "%PRONAME%"=="" echo No Contract Name Entered
if "%PRONAME%"=="" pause
cls
if "%PRONAME%"=="" goto input_PRONAME
:input_PROJLOC
set /P PROJLOC=Enter Contract Location: %=%
cls
if "%PROJLOC%"=="" echo No Contract Location Entered
if "%PROJLOC%"=="" pause
cls
if "%PROJLOC%"=="" goto input_PROJLOC
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\# Archive"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\Architects"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\Co-ord"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\Electrical"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\Mechanical"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Incoming\Structural"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Outgoing"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Outgoing\# Archive"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Outgoing\LPCB"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Outgoing\Pre-Fab"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Outgoing\AS INSTALLED"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\# Archive"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Health & Safety"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Insurance"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Programme"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Sub-Contractors"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Variations"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\Photos"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Superceeded"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\O&M"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\O&M\# Archive"
mkdir "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Technical Data"
echo New Project Folder Created
pause
xcopy "T:\Data - TFP\Administration\Company Forms & Templates\Sprinklers\(TFP.S55) [DI_SP-00000-00].dotx" "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance"
ren "%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC%\Corrispondance\(TFP.S55) [DI_SP-00000-00].dotx" "DI_%DIVCODE%-%PROJNUM%-%YEARDIG%_%PRONAME% - %PROJLOC% (0.0).dotx"


hope this makes more sense to you - as for my question on tokens i think i understand but correct if wrong

a token is a part of a line for example in the below token 1 would be pinging token 2 would be remote_PC etc

Pinging REMOTE_PC [10.100.0.14] with 32 bytes of data:

thanks for any help :)


Report •

#5
February 25, 2011 at 08:16:51
ok im getting closer i feel it :)

i found this that Mechanix2Go posted a few years ago

@echo off > newfile.txt
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (myfile.txt) do (if "%%a"=="DefaultFOV=90.000000" (echo DefaultFOV=110.00000 >> newfile.txt) else (echo %%a >> newfile.txt))


this will edit if txt file is format like

somerandomtxt
DefaultFOV=90.000000
somerandomtxt

my text doc is formated like

somerandomtxt;DefaultFOV=90.000000;somerandomtxt

where do i go from here - thanks


Report •


Ask Question