B
B
blizzard2018-02-18 15:12:04
Python
blizzard, 2018-02-18 15:12:04

Why is there a not well-formed (invalid token) error when parsing a file?

there is a folder in which there are several xml files, I try to parse them in a loop with this code:

import xml.etree.ElementTree as ET
import os
import io

xml_dir = '/home/blizzard/Documents/edi_royal canin/'
for file in os.listdir(xml_dir):
    if file.endswith('.xml'):
        tree = ET.parse(xml_dir+file)

Gives an error:
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 8, column 0
If you do it without a loop, then everything works:
path = '/home/blizzard/Documents/edi_royal canin/40-download-2018-01-12-11-18-09-3329_MZP.xml'
tree = ET.parse(path)
root = tree.getroot()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question