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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:39:10+00:00 2026-05-22T21:39:10+00:00

I have an xml file in which it is possible that the following occurs:

  • 0

I have an xml file in which it is possible that the following occurs:

...
<a><b>This is</b> some text about <c>some</c> issue I have, parsing xml</a>
...

Edit: Let’s assume, the tags could be nested more than only level, meaning

<a><b><c>...</c>...</b>...</a>

I came up with this using the python lxml.etree library.

context = etree.iterparse(PATH_TO_XML, dtd_validation=True, events=("end",))
for event, element in context:
    tag = element.tag
    if tag == "a":
        print element.text # is empty :/
        mystring = element.xpath("string()")
        ...

But somehow it goes wrong.

What I want is the whole string

"This is some text about some issue I have, parsing xml"

But I only get an empty string. Any suggestions? Thanks!

  • 1 1 Answer
  • 3 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-22T21:39:11+00:00Added an answer on May 22, 2026 at 9:39 pm

    This question has been asked many times.

    You can use lxml.html.text_content() method.

    import lxml.html
    t = lxml.html.fromstring("...")
    t.text_content()
    

    REF: Filter out HTML tags and resolve entities in python

    OR use lxml.etree.strip_tags() method.

    REF: In lxml, how do I remove a tag but retain all contents?

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

Sidebar

Related Questions

I have this xml file which has text init. i.e Hi my name is
I have an XML file which I'd like to parse into a non-XML (text)
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name
I have an 'xml file' file that has some unwanted characters in it <data>
I have a xml file which I need to open with Microsoft Word 2007.
I have an XML file which I need to parse using PHP and send
I have an XML file which XML parser choke on. A part of it
I have an XML file which has many section like the one below: <Operations>
I have an XML file which has to be transformed using XSLT, I am
I have written xml file which contains html tags as element like <component> <input

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.