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

  • Home
  • SEARCH
  • 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 8413743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:58:49+00:00 2026-06-10T00:58:49+00:00

I am writing code in python that can not only read a xml but

  • 0

I am writing code in python that can not only read a xml but also send the results of that parsing as an email. Now I am having trouble just trying to read the file I have in xml. I made a simple python script that I thought would at least read the file which I can then try to email within python but I am getting a Syntax Error in line 4.

root.tag ‘log’

Anyways here is the code I written so far:

import xml.etree.cElementTree as etree

tree = etree.parse('C:/opidea.xml')
response = tree.getroot()
log = response.find('log').text
logentry = response.find('logentry').text
author = response.find('author').text
date = response.find('date').text
msg = [i.text for i in response.find('msg')]

Now the xml file has this type of formating

  <log>
<logentry
   revision="12345">
<author>glv</author>
<date>2012-08-09T13:16:24.488462Z</date>
<paths>
<path
   action="M"
  kind="file">/trunk/build.xml</path>
</paths>
 <msg>BUG_NUMBER:N/A
FEATURE_AFFECTED:N/A
   OVERVIEW:Example</msg>
</logentry>
</log>

I want to be able to send an email of this xml file. For now though I am just trying to get the python code to read the xml file.

  • 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-10T00:58:51+00:00Added an answer on June 10, 2026 at 12:58 am

    response.find('log') won’t find anything, because:

    find(self, path, namespaces=None)

    Finds the first matching subelement, by tag name or path.

    In your case log is not a subelement, but rather the root element itself. You can get its text directly, though: response.text. But in your example the log element doesn’t have any text in it, anyway.

    EDIT: Sorry, that quote from the docs actually applies to lxml.etree documentation, rather than xml.etree.

    I’m not sure about the reason, but all other calls to find also return None (you can find it out by printing response.find('date') and so on). With lxml ou can use xpath instead:

    author = response.xpath('//author')[0].text
    msg = [i.text for i in response.xpath('//msg')]
    

    In any case, your use of find is not correct for msg, because find always returns a single element, not a list of them.

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

Sidebar

Related Questions

I'm writing some serialization/deserialization code in Python that will read/write an inheritance hierarchy from
I'm writing some code (just for fun so far) in Python that will store
Are there any guidelines to writing Google App Engine Python code that would work
I feel like I spend a lot of time writing code in Python, but
I have been writing Python code for only a couple of weeks, so I'm
I was writing a Python Code that creates dictionaries dynamically,initializes it to a reference
I'm am writing a bit of python code that gets data from a website.
I have a programming experience with statically typed languages. Now writing code in Python
I am writing Python code in Visual Studio 2010 using the excellent Python Tools
I'm writing some code which involves running a few shell commands from Python and

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.