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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:52:27+00:00 2026-06-10T14:52:27+00:00

Hello I am having trouble with a xml file I am using. Now what

  • 0

Hello I am having trouble with a xml file I am using. Now what happens is on a short xml file the program works fine but for some reason once it reaches a size ( I am thinking 1 MB)
it gives me a “IndexError: list index out of range”

Here is the code I am writing so far.

from xml.dom import minidom

import smtplib
from email.mime.text import MIMEText
from datetime import datetime

def xml_data():
    f = open('C:\opidea_2.xml', 'r')
    data = f.read()
    f.close()

    dom = minidom.parseString(data)
    ic = (dom.getElementsByTagName('logentry'))
    dom = None      
    content = ''  

    for num in ic:
        name = num.getElementsByTagName('author')[0].firstChild.nodeValue
        if name:
            content += "***Changes by:"  + str(name) + "*** " +  '\n\n     Date: '
        else:
            content += "***Changes are made Anonymously *** " +  '\n\n     Date: '
        print content

if __name__ == "__main__":
    xml_data ()

Here is part of the xml if it helps.

 <log>
 <logentry
  revision="33185">
 <author>glv</author>
 <date>2012-08-06T21:01:52.494219Z</date>
 <paths>

 <path
  kind="file"
  action="M">/branches/Patch_4_2_0_Branch/text.xml</path>   

 <path
  kind="dir"
  action="M">/branches/Patch_4_2_0_Branch</path>

</paths>
<msg>PATCH_BRANCH:N/A
 BUG_NUMBER:N/A
 FEATURE_AFFECTED:N/A
 OVERVIEW:N/A
  Adding the SVN log size requirement to the branch 
 </msg>
  </logentry>
    </log>

The actual xml file is much bigger but this is the general format. It will actually work if it was this small but once it gets bigger I get problems.

here is the traceback

Traceback (most recent call last):
  File "C:\python\src\SVN_Email_copy.py", line 141, in <module>
    xml_data ()
  File "C:\python\src\SVN_Email_copy.py", line 50, in xml_data
    name = num.getElementsByTagName('author')[0].firstChild.nodeValue
IndexError: list index out of range
  • 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-10T14:52:29+00:00Added an answer on June 10, 2026 at 2:52 pm

    Based on the code provided your error is going to be in this line:

    name = num.getElementsByTagName('author')[0].firstChild.nodeValue
    #xml node-^
    #function call -------------------------^
    #list indexing ----------------------------^
    #attribute access -------------------------------------^
    

    That’s the only place in the demonstrated code that you’re indexing into a list. That would imply that in your larger XML Sample you’re missing an <author> tag. You’ll have to correct that, or add in some level of error handling / data validation.

    Please see the code elaboration for more explanation. You’re doing a ton of things in a single line by taking advantage of the return behaviors of successive commands. So, the num is defined, that’s fine. Then you call a function (method). It returns a list. You attempt to retrieve from that list and it throws an exception, so you never make it to the Attribute Access to get to firstChild, which definitely means you get no nodeValue.

    Error checking may look something like this:

    authors = num.getElementsByTagName('author')
    if len(authors) > 0:
      name = authors[0].firstChild.nodeValue
    

    Though there are many, many ways you could achieve that.

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

Sidebar

Related Questions

Hello I am having trouble with a xml file I am using. Now what
I'm having trouble parsing this xml file using jquery: <?xml version=1.0 encoding=utf-8?> <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:BOT-Memos:-myXSD-2011-07-13T14-29-57
Hello I have been having trouble with this for a while now. I have
Hello I am having trouble using multiquery in facebook .net. I am trying to
Hello i'm having some trouble in displaying multiple pushpins on maps. So far i've
Hello I am having troubles with my jqgrid, my jqgrid loads an xml file
Im having some trouble with a linq query into an xml tree. Here is
Im having trouble with a simple hello world program lol! Im hoping someone can
Hello trying to get my website to display correctly having trouble. I am using
Hello all having some trouble accessing elements from a returned JSON from Twitter. I'm

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.