Read xml file inside a batch file

Hi,

I want to read a xml file inside a batch file to read a value in specific tag of xml file. The value read from the xml has to be stored a variable inside the batch file.Your help much appreciated.

Thanks in advance
erwagaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
The for line wrapped over two lines above but should be one there...

Steve

Ok.  Not so bad then maybe...
 
@echo off
for /f "tokens=2 delims=><" %%a in ('type test.xml ^| find "<DTSConfigDB>"') do set ip=%%a
echo The IP address is %ip%

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
Main trouble with reading something like XML from a batch file is the normal parsing is going to get messy with > and < characters in the data.  It may be easier to do this in a VB Script frankly?  is that an option?  If not will see what can be done.
0
 
Steve KnightIT ConsultancyCommented:
Can you give us the relevant line (at least) of the XML file in question please and what you want to retrieve please.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
erwagaAuthor Commented:
VBScript is not an option. Here is the xml file

<?xml version="1.0" encoding="utf-8" ?>
<ConnectionInfo>
<DTSConfigDB>10.0.244.31</DTSConfigDB>
</ConnectionInfo>


I have to read value in <DTSConfigDB>
0
 
Steve KnightIT ConsultancyCommented:
Ok.  Not so bad then maybe...

@echo off
for /f "tokens=2 delims=><" %%a in ('type test.xml ^| find

"<DTSConfigDB>"') do set ip=%%a
echo The IP address is %ip%
Steve
0
 
erwagaAuthor Commented:
It really works, thanks Steve for prompt response.
0
 
Steve KnightIT ConsultancyCommented:
No problem!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.