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 7744341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:44:41+00:00 2026-06-01T09:44:41+00:00

I have an xml file <temp> <email id=1 Body=abc/> <email id=2 Body=fre/> . .

  • 0

I have an xml file

<temp>
  <email id="1" Body="abc"/>
  <email id="2" Body="fre"/>
  .
  .
  <email id="998349883487454359203" Body="hi"/>
</temp>

I want to read the xml file for each email tag. That is, at a time I want to read email id=1..extract body from it, the read email id=2…and extract body from it…and so on

I tried to do this using DOM model for XML parsing, since my file size is 100 GB..the approach does not work. I then tried using:

  from xml.etree import ElementTree as ET
  tree=ET.parse('myfile.xml')
  root=ET.parse('myfile.xml').getroot()
  for i in root.findall('email/'):
              print i.get('Body')

Now once I get the root..I am not getting why is my code not been able to parse.

The code upon using iterparse is throwing the following error:

 "UnicodeEncodeError: 'ascii' codec can't encode character u'\u20ac' in position 437: ordinal not in range(128)"

Can somebody help

  • 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-06-01T09:44:43+00:00Added an answer on June 1, 2026 at 9:44 am

    An example for iterparse:

    import cStringIO
    from xml.etree.ElementTree import iterparse
    
    fakefile = cStringIO.StringIO("""<temp>
      <email id="1" Body="abc"/>
      <email id="2" Body="fre"/>
      <email id="998349883487454359203" Body="hi"/>
    </temp>
    """)
    for _, elem in iterparse(fakefile):
        if elem.tag == 'email':
            print elem.attrib['id'], elem.attrib['Body']
        elem.clear()
    

    Just replace fakefile with your real file.
    Also read this for further details.

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

Sidebar

Related Questions

I have a XML file that I read with Python. I want to make
I have a XML file with the following data format: <net NetName=abc attr1=123 attr2=234
I have parsed XML file into objects, in which each object has a 1:1
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an XML file (on the left) and I want to create multiple
I have an XML file format that contains a structure of questions: <question id=q101>
I have the following XML file <?xml version=1.0 ?> <Persons> <Person> <Id>1</Id> <Name>temp</Name> <Qlid>1234</Qlid>
I have a java code to read XML nodes, I want to add in
I have a bit of Java code that outputs an XML file to a
I have an XML file I'm trying to modify and want to add a

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.