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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:12:16+00:00 2026-06-14T13:12:16+00:00

I am trying to read the xml file email.xml (Data below) using the python

  • 0

I am trying to read the xml file email.xml(Data below) using the python code provided below,am not able to print the actual data present in the xml file but getting the below output. Where am I going wrong?

CURRENT OUTPUT:

xmlfile
<open file 'email.xml', mode 'r' at 0x0226AF98>
[<DOM Element: to at 0x231d620>]
[<DOM Element: cc at 0x231d6c0>]
[<DOM Element: bcc at 0x231d760>]

PYTHON CODE:

import xml.dom.minidom as minidom

def getemaildata():
    # Open the XML file
    xmlfile = open('email.xml','r')
    print "xmlfile"
    print xmlfile
    dom = minidom.parse(xmlfile)
    email=dom.getElementsByTagName('email')
    for node in email:
        toemail=dom.getElementsByTagName('to')
        print toemail
        ccemail=dom.getElementsByTagName('cc')
        print ccemail
        bccemail=dom.getElementsByTagName('bcc')
        print bccemail
return (toemail,ccemail,bccemail)

def main ():
(To,CC,BCC)=getemaildata()

 if __name__ == '__main__':
main()

email.xml file:

<email>
    <to>data@company.com;data.stability@company.com; 
         data.sns@company.com;data.pes@company.com;</to> 
    <cc> data.team </cc>
    <bcc>data@company.com</bcc>     
</email>
  • 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-14T13:12:17+00:00Added an answer on June 14, 2026 at 1:12 pm

    You are getting back lists of “Element” objects from the XML parser. You need to iterate further to get to the actual “Text” nodes.

    Eg:

    # this returns a list of all Elements that have the tag "to"
    toemail=dom.getElementsByTagName('to')
    
    # Here we take the first node returned with tag 'to', then it's first child node
    textnode = toemail[0].childNodes[0]
    
    # print the data in the textnode
    print textnode.data
    

    To clean the addresses from the text node:

    for address in textnode.data.split(';'):
        if address == '':
            # Catch empty entries as a result of trailing ;
            continue
        email = i.strip().strip('\n')
        print email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read an XML file into a data set using dataset.ReadXml(fileName,
Below is my code & xml file. I am trying to read a xml
I am trying to read an XML file using objective C language and parse
I'm trying to read data from an xml file and display it in a
I'm trying to read the data from an XML file, validating it against the
I'm trying to read in some sample data from an XML file in a
I have an xml file(from federal government's data.gov) which I'm trying to read with
Hi I am trying to read XML File using XLinq and binding the values
I am trying to read an XML file using LINQ. I have had no
I am trying to read tags from XML using LibXML. I can print all

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.