Solved

Read xml file inside a batch file

Posted on 2009-04-01
7
9,255 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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