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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:17:55+00:00 2026-05-27T23:17:55+00:00

I have a file which contains corrupt XML, There are some garbage characters at

  • 0

I have a file which contains corrupt XML, There are some garbage characters at the end of line that I want to get rid of. These garbage characters do not allow me to use Python’s XML parser. Example:

<request><pair><name>q</name><value><![CDATA[LOL]]></value></pair><pair><name>start</name><value>1</value></pair></request>�J I�i�Y�Y��'z�3�u�J�5��}���#Q/k;!�ˑ�9Q){_������ŐF
<request><pair><name>q</name><value><![CDATA[LOL2]]></value></pair><pair><name>start</name><value>1</value></pair></request>4/lIT�l��'�c�Oֲ�{�;��_?��(>͏Y�mP��

How can I remove the garbage characters after </request> ? Or in other words, How to remove string between </request> and <request> ?

Please note from <request> to </request> is just one line so

Code:

awk '/<request>/ , /<\/request>/' test.txt

does not work.

My purpose is to extract value when name is “q” (LOL and LOL2) in this case. So if that can be done easily, I am not bothered about removing the junk characters.

Thank you for your time.

  • 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-27T23:17:56+00:00Added an answer on May 27, 2026 at 11:17 pm

    you can extract data using lxml and xpath expressions-

    import lxml
    from lxml import etree
    source_xml = " path to your xml file"
    et = etree.parse(source_xml)
    value = et.xpath("//document/request/pair[name='q']/value/text()")
    print " ".join(value) 
    

    I tried this using your given xml sample and my output is 'LOL LOL2'

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

Sidebar

Related Questions

Here I have one file which contains some information, and I want to check
I have a text file which contains some numerals, for example, There are 60
I have an XML file which contains multiple nodes that have children. If the
i have a log file which contains hundreds/thousands of seperate XML messages and need
Good morning. I have an XML file which contains lists of warning and errors
We have a PageRoles xml file which contains the page path and the user
I have a file which contains several thousand numbers, each on its own line:
i have xml file which contains CDATA i need to update the CDATA as
I have file like this which contains 5 columns. But some rows in my
I have file which contains some data, like this 2011-01-02 100100 1 2011-01-02 100200

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.