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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:14:01+00:00 2026-05-23T14:14:01+00:00

I am working with some xml files. The schema for the files specifies that

  • 0

I am working with some xml files. The schema for the files specifies that there can only be one of a certain type of element (in this case I am working with the footnotes element).

There can be several footnote elements in the footnotes element, I am trying to grab and process the footnotes element so that I can iterate through it to discover the footnote elements.

here is my current approach

def get_footnotes(element_list):
    footnoteDict=od()

    footnotes_element=[item for item in element_list if item.tag=='footnotes'][0]
    for eachFootnote in footnotes_element.iter():
        if eachFootnote.tag=='footnote':
            footnoteDict[eachFootnote.values()[0]]=eachFootnote.text
    return footnoteDict

element_list is a list of elements that are relevant for me after iterating through the entire tree

So I am wondering if there is a more pythonic way to get the footnotes element instead of iterating through the list of elements it seems to me that this is clumsy with this being

footnotes_element=[item for item in element_list if item.tag=='footnotes'][0]
  • 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-23T14:14:01+00:00Added an answer on May 23, 2026 at 2:14 pm

    Something like this should do the job:

    from lxml import etree
    
    xmltree = etree.fromstring(your_xml)
    
    for footnote in xmltree.iterfind("//footnotes/footnote"):
       # do something
       pass
    

    It’s easier to help if you provide some sample XML.

    Edit:

    If you are working with really big files, you might want to look into iterparse.

    This question seems to have quite a nice example: python's lxml and iterparse method

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

Sidebar

Related Questions

I'm working on a project involving some large XML files (from 50MB to over
I'm working with some xml 'snippets' that form elements down the xml. I have
I'm working with some schema which defines an abstract complex type, eg. <xs:complexType name=MyComplexType
I've got some XML files that recently changed so that some of the nodes
I'm working on some GWT 2.4 uiBinder xml files and I'm seeing errors under
Greetings! I'm working on wrapping my head around LINQ. If I had some XML
I am working on some Plesk integration using the XML API and I am
I'm relatively new to working with XML and am working with some rather large
Working on some tweaks for a build script, I noticed that the output from
Whilst working on some generally horrible Javascript code this morning, I came across the

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.