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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:32:56+00:00 2026-05-14T02:32:56+00:00

Bit of a beginner question here: Say I have a block of xml: <root>

  • 0

Bit of a beginner question here:

Say I have a block of xml:

<root>
 <district>
  <house><room><door/><room></house>
 </district>
 <district>
  <street>
   <house>and so on</house>
  </street>

etc.

With ElementTree I can do:

houses=doc.findall(".//house")

to select all the house nodes, regardless of their parent. What I want to do now is turn each of the house nodes into a separate tree object.

Part of the reason for doing this is that I then want to do another find:

door=houseXml.findall(".//door")

I can do something like:

for _house in houses:
    houseXml=_house.getiterator

but this doesn’t seem to do what I want.

Where am I going wrong?

  • 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-05-14T02:32:56+00:00Added an answer on May 14, 2026 at 2:32 am

    You can call findall on the elements returned by the first findall:

    >>> doc = """<root>
    ...  <district>
    ...   <house><room><door/></room></house>
    ...  </district>
    ...  <district>
    ...   <street>
    ...    <house>and so on</house>
    ...   </street>
    ...  </district>
    ... </root>"""
    >>>
    >>> from xml.etree import cElementTree as ET
    >>>
    >>> r = ET.XML(doc)
    >>>
    >>> for house in r.findall('.//house'):
    ...   print house, house.findall('.//door')
    ...
    <Element 'house' at 0xb7f3ea70> [<Element 'door' at 0xb7f3eab8>]
    <Element 'house' at 0xb7f3eb00> []
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey bit of a beginners question here, I have connected to an imap server
A beginner's question. I have a bit of rich HTML inside a hidden div,
Bit of an unusual question, but I have setup a field inside a MySQL
Bit of a strange question here i know. but i wanted to know if
Bit support question. Apologies for that. I have an application linked with GNU readline.
I have another beginner's question that hopefully someone can help with. I'm trying to
A beginner question: I don't know how best to structure this bit of code,
I'm a bit new to web development so forgive the slightly beginner question. Can
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input
I am a beginner with Qt, so my question might be a bit basic.

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.