Solved

Read xml file inside a batch file

Posted on 2009-04-01
7
9,667 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

628 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