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:
---------------------------------------------------------------------------------------------------------------
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 :
I have imported xml.etree.ElementTree for both the codes. Also I have attached the screenshot of
XML file for reference.
import xml.etree.ElementTree as ET
I want to get particular elements of the XML data.
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

XML file for reference.
import xml.etree.ElementTree as ET
I want to get particular elements of the XML data.