Hey gurus,
I'm trying to copy sections in a file within a set of XML tags
> <tag>I want to copy the data here</tag>`
- Please note I found out the data around the tags is not valid XML so I can't import a normal library and have to find it via string comparison :( *
There are multiple sections of text I want to extract in the file so I'm trying to loop through the file to find each one. I just wanted to do this on a line-by-line basis till I figured out how to parse the lines of unwanted text and created the following code:
InputFile=open('xml_input_File.xml','r')
OutputFile=open('xml_output_file.xml', 'w')
check = 0
for line in InputFile.readlines():
if line.find("<STARTTAG>"):
check = 1
elif line.find(r"<//STARTTAG>"):
check = 0
if check == 1:
OutputFile.write(line)
The problem I'm having is it simply copies the whole file and not just the sections I would like.
I know the code is not very pretty but I'm still learning and its going to be a "d'oh!" moment but thanks for your help!!
Cheers