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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:35:23+00:00 2026-06-09T09:35:23+00:00

Please help, Python beginner, after getting all the data from xml, data_list = xmlTree.findall(‘.//data’)

  • 0

Please help, Python beginner,

after getting all the data from xml,
data_list = xmlTree.findall(‘.//data’)
e.g here I get 10 rows
Now, I need to keep only a few rows for which attribute ‘name’ values match with elements of another list (inputID) with three IDs inside.
e.g. remains only 3 rows whose name attribute match with the list elements

Thank you.

  • 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-09T09:35:25+00:00Added an answer on June 9, 2026 at 9:35 am

    You can use a for loop to iterate over each element, then decide if each element should be removed. I used the Python doc ElementTree XML API for reference.

    from xml.etree.ElementTree import ElementTree
    
    tree = ElementTree()
    
    # Test input
    tree.parse("sample.xml")
    
    # List containing names you want to keep
    inputID = ['name1', 'name2', 'name3']
    
    for node in tree.findall('.//data'):
        # Remove node if the name attribute value is not in inputID
        if not node.attrib.get('name') in inputID:
            tree.getroot().remove(node)
    
    # Do what you want with the modified xml
    tree.write('sample_out.xml')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could you please help me converting this c++ code into python: I am trying
Please help me to discover whether this is a bug in Python (2.6.5), in
Could you please help me to find the problem? Python code that works: class
Please help me in clarifying the concept of these two python statements in terms
Given the python code below, please help me understand what is happening there. start_time
I have a python problem, I'm reading from XML and have two spread functions
I am new dummy to python...please help me in the following problem I have
Can someone please help me convert the following two lines of python to C#.
Here comes again, I have managed to collect specific data from resx file (xml)
I am a beginner struggling with Python every day. I have a large data

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.