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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:19:43+00:00 2026-06-10T15:19:43+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 whenever i try to get the msg tag i get an error preventing me from accessing the data. 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:

    xmlDate = num.getElementsByTagName('date')[0].firstChild.nodeValue

    content += xmlDate + '\n '

    xmlMsg = num.getElementsByTagName('msg')


    if xmlMsg !='' and len(xmlMsg) > 0:
        xmlMsgc = xmlMsg[0].firstChild.nodeValue
        content += "   Comments: \n        " + str(xmlMsg) + '\n\n'

    else:
        xmlMsgc = "No comment made."

        content += xmlMsgc

  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>

Now when i use xmlMsg = num.getElementsByTagName('msg')[0].toxml() I can get the code to work, I just have to do a lot of replacing and I rather not have to do that. Also I have date working using xmlDate = num.getElementsByTagName('date')[0].firstChild.nodeValue.

Is there something I am missing or doing wrong? Also 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 94, in xml_data
    xmlMsg = num.getElementsByTagName('msg').firstChild.nodeValue
AttributeError: 'NodeList' object has no attribute 'firstChild'
  • 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-10T15:19:45+00:00Added an answer on June 10, 2026 at 3:19 pm

    I suggest a different approach. Below is a program that does what you want (I think…). It uses the ElementTree API instead of minidom. This simplifies things quite a bit.

    You have posted several related questions concerning parsing of an XML file using minidom. I really think you should look into ElementTree (and for even more advanced stuff, check out ElementTree’s “superset”, lxml). Both these APIs are much easier to work with than minidom.

    import xml.etree.ElementTree as ET
    
    def xml_data():
        root = ET.parse("opidea_2.xml")
        logentries = root.findall("logentry")
        content = ""
    
        for logentry in logentries:
            date = logentry.find("date").text
            content += date + '\n '
            msg = logentry.find("msg")
            if msg is not None:
                content += "   Comments: \n        " + msg.text + '\n\n'
            else:
                content += "No comment made."
    
        print content
    
    if __name__ == "__main__":
        xml_data()
    

    Output when using your XML sample (you may want to work a bit more on the exact layout):

    2012-08-06T21:01:52.494219Z
        Comments: 
            PATCH_BRANCH:N/A
     BUG_NUMBER:N/A
     FEATURE_AFFECTED:N/A
     OVERVIEW:N/A
      Adding the SVN log size requirement to the branch 
    
    • 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 trying to get my website to display correctly having trouble. I am using
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 am having troubles with my jqgrid, my jqgrid loads an xml file
Hello all I am having trouble uploading my blackberry alx file to the blackberry.
Hello I'm having trouble with the following piece of code: <h:selectOneMenu id=selectTipoAutorizacion value=#{autorizacion.codigoTipoAutorizacion} required=true>
Hello i am having trouble with passing a php return value to the innerHTML
Hello I am having a problem with the numbering of figures using Latex, I

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.