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

The Archive Base Latest Questions

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

I am trying to parse an XML file using Python. Due to the size

  • 0

I am trying to parse an XML file using Python. Due to the size of the XML, I want to use a Pull Parser. I found this one.

My code starts with

doc = pulldom.parse("myfile.xml")
for event, node in doc:
    # code here...

I am using

if (node.localName == "b"):

to get the XML tag name, and it works fine.

What I can’t find how to do is get the text from between the tags. Using node.nodeValue returns None.

I can use node.toxml() to get the full XML for the node, but I only want the text between the tags. Is there a way to do this other than using a regex replace to take the tags out of node.toxml()?

  • 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-14T17:30:13+00:00Added an answer on June 14, 2026 at 5:30 pm

    You have two nodes with local name “b” for every tag with text – a START_ELEMENT and an END_ELEMENT. Normally you should receive something like this:

    START_ELEMENT
    CHARACTERS
    END_ELEMENT
    

    So you are looking for the characters after a matching start-element. You may want to try something like this:

    from xml.dom.pulldom import CHARACTERS, START_ELEMENT, parse
    
    doc = parse("myfile.xml")
    text_expected = False
    for event, node in doc:
        print event, node
        if text_expected:
            text_expected = False
            if event != CHARACTERS:
                # strange .. there should be some
                continue
            print node.data
        else:
            text_expected = (event == START_ELEMENT) and (node.localName == "b")
    

    With this myfile.xml

    <a>
        <b>c1</b>
        <b>c2</b>
    </a>
    

    I get the output

    c1
    c2
    

    Note that you might need to strip() each string and you must ignore every other CHARACTERS-event. Every linebreak and whitespace between two elements generate a CHARACTERS-event.

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

Sidebar

Related Questions

I'm trying to parse a XML file using TBXML . However, this parser has
I am trying to parse an XML file with python using lxml, but get
I'm trying to parse an xml file with PHP. I'm using this code and
I am trying to parse a xml file using dom parser. The xml fles
I'm using NSXmlParser and trying to parse this XML file: <api> <query> <normalized> <n
I want to parse an XML file from URL using JDOM. But when trying
Trying to parse the following Python file using the lxml.etree.iterparse function. sampleoutput.xml <item> <title>Item
I am trying to parse an XML file using NSXMLParser, but the method [parser
I'm trying to learn how to parse an xml file using SAX parser in
I am Trying To Use NSXMLParser to parse an xml file using cocoa which

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.