0

Is it possible to put a Python output into an XML?

The code I have so far is:

with open('logfile.txt', 'r') as StationLog:
    for line in StationLog:
        header = line.split('=')[0]
        if line.split('=')[0].strip() == 'name':
            name = line.split('=')[1].strip().lower()
            print name
        elif line.split('=')[0].strip() == 'siteIP':
            siteIP = line.split('=')[1].strip().rstrip('"').lstrip('"')
            print siteIP
        elif line.split('=')[0].strip() == 'id':
            id = line.split('=')[1].strip()
            print id

The ouput is:
abcd
192.168.1.1
123

My desired input is:

<Station>
    <name>abcd</name>
    <siteIP>192.168.1.1</siteIP>
    <id>123</id>
</Station>
martineau
  • 119,623
  • 25
  • 170
  • 301
e.c.husk
  • 33
  • 1
  • 5

0 Answers0