I am beginner in python. I am struggling with a problem which is explained below. I am sharing incomplete python script also which does not work for this problem. I would be grateful if get support or instruction for my script.
File looks like this:
<Iteration>
<Iteration_hit>Elememt1 Element1
abc1 hit 1
.
.
</Iteration>
<Iteration>
<Iteration_hit>Elememt2 Element2
abc2 hit 1
.
.
</Iteration>
<Iteration>
<Iteration_hit>Elememt3 Element3
abc3 hit 1
.
.
</Iteration>
<Iteration>
<Iteration_hit>Elememt4 Element4
abc4 hit 1
.
.
</Iteration>
I need from <Iteration>
to </Iteration>
for Elements list match, which means for Element2 and Element4 the output file should look like this:
<Iteration>
<Iteration_hit>Elememt2 Element2
abc2 hit 1
.
.
</Iteration>
<Iteration>
<Iteration_hit>Elememt4 Element4
abc4 hit 1
.
.
</Iteration>
Script
#!/usr/bin/python
x = raw_input("Enter your xml file name: ")
xml = open(x)
l = raw_input("Enter your list file name: ")
lst = open(l)
Id = list()
ylist = list()
import re
for line in lst:
stuff=line.rstrip()
stuff.split()
Id.append(stuff)
for ele in Id:
for line1 in xml:
if line1.startswith(" <Iteration_hit>"):
y = line1.split()
# print y[1]
if y[1] == ele: break