1 year ago

#36093

test-img

Kanika Singla

How to resolve- xml.parsers.expat.ExpatError: junk after document element- even after having single root element

my xml structure has one single root element. but

xmltodict.parse(request) is giving me this error- xml.parsers.expat.ExpatError: junk after document element.

Although it does run successfully sometimes, and sometimes throws the error. The XML file I'm using is same everytime. I've tried using other xml to json/dict parsers and still getting same issue.

Please help me figure out how to fix this.

xml data format-


<?xml version='1.0' encoding='UTF-8'?>
<results preview='0'>
<meta>
<fieldOrder>
<field>attrs.env</field>
<field>db</field>
<field>type</field>
<field>StartTime</field>
<field>EndTime</field>
<field>status</field>
<field>info_max_time</field>
<field>info_min_time</field>
<field>info_search_time</field>
<field>info_sid</field>
</fieldOrder>
</meta>
</results>  

I've stored this in a variable requests. Getting the error while running:

xmltodict.parse(request)

python

xml

xml-parsing

xmltodict

0 Answers

Your Answer

Accepted video resources