Hello all,
Could someone please give me a guidance of how to write a batch file that would read an xml file, and then copy the text that in bewtween <label>...........</lablel>, and then write it to a new file? Thank you so much for your help.
Read a xml file and copy a perticular text to a new file
Moderator: DosItHelp
Re: Read a xml file and copy a perticular text to a new file
loc3loan wrote:Hello all,
Could someone please give me a guidance of how to write a batch file that would read an xml file, and then copy the text that in bewtween <label>...........</lablel>, and then write it to a new file? Thank you so much for your help.
Well you could search the forums as this questioned has been asked before. But without seeing an example of the real file most people will be gun shy to start coding a script for you.
Re: Read a xml file and copy a perticular text to a new file
Code: Select all
@echo off
set "in=D:\Test\example.xml"
set "out=D:\Test\new.txt"
set "from=^<label^>"
set "to=^</lablel^>"
type "%in%">.tmp
mshta "vbscript:CreateObject("Scripting.FileSystemObject").GetStandardStream(1).Write(Split(Split(CreateObject("Scripting.FileSystemObject").OpenTextFile(".tmp").ReadAll(),"%from%")(1),"%to%")(0))&Close()">"%out%"
del .tmp
exit /b
Re: Read a xml file and copy a perticular text to a new file
XML files come in different flavours, and this will work for some of them:
This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
(There is a recently updated version of REPL.BAT on this forum - am waiting to see if any further changes will be made, but the one above will work)
Code: Select all
type "file.xml" | repl ".*<label>(.*?)</label>.*" "$1" a >"newfile.txt"
This uses a helper batch file called `repl.bat` (by dbenham) - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
Place `repl.bat` in the same folder as the batch file or in a folder that is on the path.
(There is a recently updated version of REPL.BAT on this forum - am waiting to see if any further changes will be made, but the one above will work)