2 days ago I first became acquainted with Python (and programming in general). Today I am stuck. I spent several hours trying to find the answer to what, I suspect, is a problem so trivial that no one is stuck here :)
The boss wants me to manually clean up the HUGE .xml files into something more human readable. I am trying to create a script to do this for me. Below is an example .xml file, as well as my desired result.
Input (File.xml):
<IssueTracking> <Issue> <SequenceNum>123</SequenceNum> <Subject>Subject of Ticket 123</Subject> <Description>Line 1 in Description field of Ticket 123. Line 2 in Description field of Ticket 123. Line 3 in Description field of Ticket 123.</Description> </Issue> <Issue> <SequenceNum>124</SequenceNum> <Subject>Subject of Ticket 124</Subject> <Description>Line 1 in Description field of Ticket 124. Line 2 in Description field of Ticket 124. Line 3 in Description field of Ticket 124.</Description> </Issue> </IssueTracking>
Output Required:
123 Subject of Ticket 123 Line 1 in Description field of Ticket 123. Line 2 in Description field of Ticket 123. Line 3 in Description field of Ticket 123. 124 Subject of Ticket 124 Line 1 in Description field of Ticket 124. Line 2 in Description field of Ticket 124. Line 3 in Description field of Ticket 124.
Here is what I got so far.
with open(File.xml, 'r') as SourceFile:
I am stuck in defining and saving these three lines between the <Description>
tags into one line that I can print before continuing with the original file. Now, having looked at dozens of other examples of line reading cycles, I suspect that I need to indicate that the point I reached in the destination field and put a new reading cycle in it. But I did not find another example of this, so I assume that I have something missing or there is a better way. Thank you in advance!
source share