pythonhtml-xml-utils

xml2csv package error '_IterParseIterator' object has no attribute 'next'


I am using xmlutils package to convert xml file to csv. My code is following :

from xmlutils.xml2csv import xml2csv as x
input_path='/media/ishan/Local Disk/doc.xml'
output_path='media/ishan/Local Disk/d.csv'
data=x(input_path,output_path,encoding='utf-8')

The above code works fine. But when I type :

data.convert(tag="sku")

It is showing following error :

AttributeError                            Traceback (most recent call last)
<ipython-input-27-f15935c368f9> in <module>()
----> 1 data.convert(tag="PIES")

/home/ishan/.local/lib/python3.5/site-packages/xmlutils/xml2csv.py in convert(self, tag, delimiter, ignore, noheader, limit, buffer_size, quotes)
 55 
 56                 # get to the root
---> 57                 event, root = self.context.next()
 58 
 59                 items = []

AttributeError: '_IterParseIterator' object has no attribute 'next'

I am not able to understand what I am doing wrong. I am totally new to this package. Why I am getting this error ? If you can suggest any other way to convert xml file into csv that will also be helpful for me. Thanks in advance.


Solution

  • You're probably using Python 3x, as it's stated here. Just change line 57 in xml2csv.py from this: event, root = self.context.next() to this: event, root = self.context.__next__()