computing
  • 0

Batch Script To Read .Xml

  • 0

Hello Experties,

I am bit new in batch scriptting,

I am trying to retrieve string from myfile.xml into variable.

I want to have only Date (01/01/2010 )

myfile.xml

<Main>
<Header FileDate=”01/01/2000″/>
<Body Type=”Firm”>
<Dept Firmid=”0123″ Name=”abc”/>
</Body>
<Trailer RecordCount=”1″>
</Main>

for that I am using

for /F “tokens=2 delims= ” %%i IN (‘findstr /L “FileDate” D:\temp\myfile.xml) do call set var1=%%i

set loaddate= %var1:~10,10%

echo %loaddate%

once it will get load in var1 i have to run java command by passing parameter value of loaddate.

javacommand %var1%

but I am not getting date(01/01/2010) in var1

Please heelp me out to solve this problem.

Really appereciate in advance for any suggesion.

stad.

Share

1 Answer

  1. I cheated a bit by setting up another delimiter, essentially
    erasing the “>” from the input string:

    for /F "tokens=2 delims=^> " %%i IN (...
    

    the carat (^) escapes the function of “>”, a special character
    which typically redirects output. Hope this helps!

    Also note that I added the closing ‘ within the IN ( ) statement, and removed the space after the = in “set loaddate=”, but perhaps the embedded space is indeed wanted…

    • 1