Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read xml file inside a batch file

Posted on 2009-04-01
7
Medium Priority
?
10,034 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:erwaga
  • 5
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24036874
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24036888
Can you give us the relevant line (at least) of the XML file in question please and what you want to retrieve please.
0
 

Author Comment

by:erwaga
ID: 24036932
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 24037061
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
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 24037071
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
 

Author Closing Comment

by:erwaga
ID: 31565210
It really works, thanks Steve for prompt response.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24037925
No problem!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question