Solved

Parse an XML file

Posted on 2016-10-12
4
31 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
4 Comments
 
LVL 32

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 32

Accepted Solution

by:
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
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 32

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 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

15 Experts available now in Live!

Get 1:1 Help Now