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

x
?
Solved

Parse an XML file

Posted on 2016-10-12
4
Medium Priority
?
67 Views
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 "https://energy.epipelines.com/businessapps/welcome.html" returned. Unfortunately it has to be a batch file.

Here is my XML file:
<Environment>
		<Variable>
			<Name>DEV2_BUSINESSAPPS_URL</Name>
			<Value><![CDATA[https://energy.epipelines.com/businessapps/welcome.html]]></Value>
		</Variable>
		<Variable>
			<Name>DEV3_BUSINESSAPPS_URL</Name>
			<Value><![CDATA[https://energy.epipelines.com/businessapps/welcome.html]]></Value>
		</Variable>
		<Variable>
			<Name>QA1_BUSINESSAPPS_URL</Name>
			<Value><![CDATA[https://qa1comapps.elm.com/businessapps]]></Value>
		</Variable>
		<Variable>
			<Name>Firefox</Name>
			<Value>Firefox.exe</Value>
		</Variable>
</Environment>

Open in new window

0
Comment
Question by:Jeff Melies
  • 2
3 Comments
 
LVL 36

Expert Comment

by:ste5an
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?
0
 
LVL 33

Accepted Solution

by:
shalomc earned 2000 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
lookup='QA1_BUSINESSAPPS_URL'

# 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"):
	name=variable.find("Name").text
	value=variable.find("Value").text
	if name==lookup:
		print name, value

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

Open in new window

1
 
LVL 33

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

877 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