Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6665735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:45:16+00:00 2026-05-26T02:45:16+00:00

import xml.etree.ElementTree as ET xmldata = file(‘my_xml_file.xml’) tree = ET.parse(xmldata) root = tree.getroot() root_iter

  • 0
import xml.etree.ElementTree as ET
xmldata = file('my_xml_file.xml')

tree = ET.parse(xmldata)
root = tree.getroot()
root_iter = root.iter()

Now I can call root_iter.next() and get my Element objects. The problem is the real file I am working with is huge and I can’t fit all of it in memory. So I am trying to use:

parse_iter = ET.iterparse(xmldata)

If I call parse_iter.next() it raises the following

Traceback (most recent call last):
  File "<pyshell#38>", line 1, in <module>
    parse_iter.next()
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1260, in next
    self._root = self._parser.close()
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1636, in close
    self._raiseerror(v)
  File "C:\Python27\lib\xml\etree\ElementTree.py", line 1488, in _raiseerror
    raise err
ParseError: no element found: line 1, column 0

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:45:17+00:00Added an answer on May 26, 2026 at 2:45 am

    The code I had was perfectly fine, except I was calling ElementTree.iterparse() on a file object I had already read with ElementTree.parse(). D’oh!

    enter image description here

    So for those who happen to make the same mistake, the solution is to either open a new file object or use file.seek(0) to reset the file cursor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to parse a file with xml.etree.ElementTree : import xml.etree.ElementTree as
import urllib import xml.etree.ElementTree as ET def getWeather(city): #create google weather api url url
I'm using cElementTree to parse an xml file. Using the .getroot() function gives an
please consider this code: import xml.etree.ElementTree as ET import urllib XML_response = urllib.urlopen('http://www.navlost.eu/aero/metar/?icao=LWSK&dt0=2011-05-03+12%3A00%3A00&c=1&rt=metar').read() tree
I am trying to use xml.etree.ElementTree to parse responses from eBay finding API, findItemsByProduct.
I have tho following code fragment: from xml.etree.ElementTree import fromstring,tostring mathml = fromstring(input) for
Here's the code I have: from cStringIO import StringIO from lxml import etree xml
I have the following Python code: import xml.dom.minidom import xml.parsers.expat try: domTree = ml.dom.minidom.parse(myXMLFileName)
I am having the below code. import xml.dom.minidom def get_a_document(name): return xml.dom.minidom.parse(name) doc =
I try to parse an xml file. The text which is in tags is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.