Solved

Read xml file inside a batch file

Posted on 2009-04-01
7
9,080 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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 500 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now