Python Forum
looking for sample py to read from txt file into XML using lxml import etree
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looking for sample py to read from txt file into XML using lxml import etree
#1
sample py to read from txt file into XML using lxml import etree
code is below
from lxml import etree
import csv

root = etree.Element('data')
rdr = open('input1.txt','rb')
header = next(rdr)
for row in rdr:
     eg = etree.SubElement(root, 'eg')
     for h, v in zip(header, row):
         etree.SubElement(eg, h).text = v

f = open(r"C:\temp\input1.xml", "w")
f.write(etree.tostring(root))
f.close()
Reply
#2
Is this meant as a question? A tutorial? Something else?
Reply
#3
i am looking for help to achieve above sample is not working
Reply
#4
looking for sample py to read from txt file into XML using lxml import etree,
i am re-posting as my question was clear in my previous post.
Please help me
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Connecting to Remote Server to read contents of a file ChaitanyaSharma 1 358 May-03-2024, 07:23 AM
Last Post: Pedroski55
  Recommended way to read/create PDF file? Winfried 3 3,044 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  python Read each xlsx file and write it into csv with pipe delimiter mg24 4 1,734 Nov-09-2023, 10:56 AM
Last Post: mg24
  read file txt on my pc to telegram bot api Tupa 0 1,227 Jul-06-2023, 01:52 AM
Last Post: Tupa
  parse/read from file seperated by dots giovanne 5 1,220 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Formatting a date time string read from a csv file DosAtPython 5 1,544 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  xml file editing with lxml.etree FlavioBueno 2 784 Jun-09-2023, 02:00 PM
Last Post: FlavioBueno
  How do I read and write a binary file in Python? blackears 6 7,764 Jun-06-2023, 06:37 PM
Last Post: rajeshgk
Video doing data treatment on a file import-parsing a variable EmBeck87 15 3,125 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Read csv file with inconsistent delimiter gracenz 2 1,308 Mar-27-2023, 08:59 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020