Parse an XML file

Posted on 2016-10-12
Last Modified: 2016-11-01
I'm trying to parse an XML file, I need to be able to pass a single parameter to a batch file "DEV2_BUSINESSAPPS_URL", if found I want the "" returned. Unfortunately it has to be a batch file.

Here is my XML file:

Open in new window

Question by:Jeff Melies
  • 2
LVL 33

Expert Comment

ID: 41841669
A batch (file) is a collection of directives for an interpreter. What interpreter do you have in mind? bash, csh, zsh, 4nt, cmd, ps?
LVL 33

Accepted Solution

shalomc earned 500 total points (awarded by participants)
ID: 41841736
In any scenario you will need an XML parser.
You could write code in your favourite language and run it in batch. Alternatively create a XSLT or Xquery and use an external tool like Saxon to run it.  

Here is an example in python. Python has executables on all platforms.
import  xml.etree.ElementTree as  xml

# you should pass is as a parameter

# assuming the xml file is called env.xml
e = xml.parse('env.xml').getroot()

# the naive way, but it works
for variable in e.findall("Variable"):
	if name==lookup:
		print name, value

# use xpath to search		
for variable in e.findall("./*[Name='%s']" % (lookup) ):
	print name, value

Open in new window

LVL 33

Expert Comment

ID: 41868071
No further input from author, but it is a valid solution.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Optimum versions of Selenium Webdriver with Python On Windows 7 1 78
How to read XML file attributes... 17 52
How can I assign SimpleXMLElements to variables? 5 53
XSLT Help 12 28
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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