Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to parse xml file
#1
Hi All,

Good Day.. I am a beginner to python, so please bear with me.

I am trying to read a XML file and parse it but am getting traceback.
code snippet:
fname = input('Enter file name: ')
stuff = ET.parse(fname)


Traceback is:
Error:
File "tracks.py", line 48, in <module> stuff = ET.parse(fname) File "C:\Users\avi\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1197, in parse tree.parse(source, parser) File "C:\Users\avi\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 598, in parse self._root = parser._parse_whole(source) xml.etree.ElementTree.ParseError: mismatched tag: line 193, column 2


---------------------------------------------------------------------------------------------------------------

Second thing I am trying is to read file and convert from string to bytes (successful) but unable to create list using fromstring().
code snippet:
fname=input("Enter File Name: ")
fdata=open(fname).read().encode('utf-8')
#print(type(fdata))
pdata=ET.fromstring(fdata)
print(type(pdata))


Traceback is :
Error:
Traceback (most recent call last): File "Assignment_15_2.py", line 41, in <module> pdata=ET.fromstring(fdata) File "C:\Users\avi\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1315, in XML parser.feed(text) xml.etree.ElementTree.ParseError: mismatched tag: line 193, column 2


I have imported xml.etree.ElementTree for both the codes. Also I have attached the screenshot of İmage
XML file for reference.
import xml.etree.ElementTree as ET

I want to get particular elements of the XML data.
Reply
#2
This thread might help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parse json field from csv file lebossejames 4 669 Nov-14-2023, 11:34 PM
Last Post: snippsat
  parse/read from file seperated by dots giovanne 5 1,044 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Trying to parse only 3 key values from json file cubangt 8 3,339 Jul-16-2022, 02:05 PM
Last Post: deanhystad
  Unable to upload file using FTP korenron 2 2,422 Dec-23-2021, 12:44 PM
Last Post: korenron
  Unable to capture all images of a multipage TIFF file in a merge bendersbender 0 2,178 Nov-19-2020, 03:09 PM
Last Post: bendersbender
  unable to write to log file Mekala 2 2,046 Aug-12-2020, 11:02 PM
Last Post: Mekala
  Parse encrypted xml file to csv Mekala 2 2,175 May-30-2020, 12:23 AM
Last Post: Mekala
  How can i parse a log file to JSON. menarcarlos 2 2,373 May-26-2020, 10:23 AM
Last Post: buran
  Read csv file, parse data, and store in a dictionary markellefultz20 4 4,487 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Parse data from xml file klllmmm 9 9,267 Jun-25-2019, 05:14 PM
Last Post: heiner55

Forum Jump:

User Panel Messages

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