Importing xml files with an encoder element at the start(using lxml)

I have a file trace.xml.The very first line in this file is<?xml version="1.0" encoding="UTF-8"?>.I tried reading the data using the following command:

with open('trace.xml') as fobj:
root = etree.fromstring(xml)

This however yields the following error:ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration. I am assuming its because of the very first tag i mentioned above.Is there a way around this any help would be appreciated.

Read more here:

Content Attribution

This content was originally published by Sreeram M at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: