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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:36:30+00:00 2026-06-17T22:36:30+00:00

I have the following code to parse an XML but it just won’t let

  • 0

I have the following code to parse an XML but it just won’t let me iterate through the children:

import urllib, urllib2, re, time, os
import xml.etree.ElementTree as ET 

def wgetUrl(target):
    try:
        req = urllib2.Request(target)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3 Gecko/2008092417 Firefox/3.0.3')
        response = urllib2.urlopen(req)
        outtxt = response.read()
        response.close()
    except:
        return ''
    return outtxt

newUrl = 'http://feeds.rasset.ie/rteavgen/player/playlist?showId=10056467'

data = wgetUrl(newUrl)
tree = ET.fromstring(data)
#tree = ET.parse(data)
for elem in tree.iter('entry'):
    print elem.tag, elem.attrib

Now, If I remove ‘entry’ from the iter I get an output like this (Why the URL??):

{http://www.w3.org/2005/Atom}entry {}
{http://www.w3.org/2005/Atom}id {}
{http://www.w3.org/2005/Atom}published {}
{http://www.w3.org/2005/Atom}updated {}
{http://www.w3.org/2005/Atom}title {'type': 'text'}

But, If I put the iter statement like this it still does not find the children to entry:

for elem in tree.iter('{http://www.w3.org/2005/Atom}entry'):
    print elem.tag, elem.attrib

I still only get the entry element on it’s own, not the children:

{http://www.w3.org/2005/Atom}entry {}

Any idea what I am doing wrong?

I have searched everywhere but can’t figure this out… I am new to all this so sorry if it is something stupid.

  • 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-17T22:36:32+00:00Added an answer on June 17, 2026 at 10:36 pm

    If you are parsing a Atom feed, you really want to use the feedparser library instead, which takes care of all these details for you and many more.

    The {http://www.w3.org/2005/Atom} part is a namespace. You need to specify that namespace to select the entry tags:

    for elem in tree.iterfind('ns:entry', {'ns': 'http://www.w3.org/2005/Atom'}):
    

    where I used a dictionary to map the ns: prefix to the namespace, or you can use the same curly braces syntax:

    for elem in tree.iterfind('{http://www.w3.org/2005/Atom}entry'):
    

    Once you have the element, you still need to explicitly find it’s children:

    for elem in tree.iterfind('{http://www.w3.org/2005/Atom}entry'):
        for child in elem:
            print child
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following XML code that I'm trying to parse, but I'm sure
Newbie to C# here.... I have the following code: var xdoc = XDocument.Parse(xml); var
I have the following code : XDocument xResponse = XDocument.Parse(strXMLResponse); var vMyData = from
I have used following code to convert string to json and parse it. String
I have following code for loading image from url in xml parsing endElement method
I'm trying to parse the following XML data: http://pastebin.com/UcbQQSM2 This is just an example
I am writing some code to parse an xml file of the following format
I have a simple but huge xml file like below. I want to parse
I have following XML code <?xml version=1.0 encoding=windows-1250?> <menu> <item> <id>0</id> <name>Pizzerie u soudu</name>
I have an issue parsing an XML feed - The following code attempts to

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.