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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:44:02+00:00 2026-06-06T16:44:02+00:00

This is the sample xml document : <bookstore> <book category=COOKING> <title lang=english>Everyday Italian</title> <author>Giada

  • 0

This is the sample xml document :

<bookstore>
    <book category="COOKING">
        <title lang="english">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <year>2005</year>
        <price>300.00</price>
    </book>

    <book category="CHILDREN">
        <title lang="english">Harry Potter</title>
        <author>J K. Rowling </author>
        <year>2005</year>
        <price>625.00</price>
    </book>
</bookstore>

I want to extract the text without specifying the elements how can i do this , because i have 10 such documents. I want so because my problem is that user is entering some word which I don’t know , it has to be searched in all of the 10 xml documents in their respective text portions. For this to happen I should know where the text lies without knowing about the element. One more thing that all these documents are different.

Please Help!!

  • 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-06T16:44:03+00:00Added an answer on June 6, 2026 at 4:44 pm

    You could simply strip out any tags:

    >>> import re
    >>> txt = """<bookstore>
    ...     <book category="COOKING">
    ...         <title lang="english">Everyday Italian</title>
    ...         <author>Giada De Laurentiis</author>
    ...         <year>2005</year>
    ...         <price>300.00</price>
    ...     </book>
    ...
    ...     <book category="CHILDREN">
    ...         <title lang="english">Harry Potter</title>
    ...         <author>J K. Rowling </author>
    ...         <year>2005</year>
    ...         <price>625.00</price>
    ...     </book>
    ... </bookstore>"""
    >>> exp = re.compile(r'<.*?>')
    >>> text_only = exp.sub('',txt).strip()
    >>> text_only
    'Everyday Italian\n        Giada De Laurentiis\n        2005\n        300.00\n
      \n\n    \n        Harry Potter\n        J K. Rowling \n        2005\n        6
    25.00'
    

    But if you just want to search files for some text in Linux, you can use grep:

    burhan@sandbox:~$ grep "Harry Potter" file.xml
            <title lang="english">Harry Potter</title>
    

    If you want to search in a file, use the grep command above, or open the file and search for it in Python:

    >>> import re
    >>> exp = re.compile(r'<.*?>')
    >>> with open('file.xml') as f:
    ...     lines = ''.join(line for line in f.readlines())
    ...     text_only = exp.sub('',lines).strip()
    ...
    >>> if 'Harry Potter' in text_only:
    ...    print 'It exists'
    ... else:
    ...    print 'It does not'
    ...
    It exists
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document with some sample content like this: <someTag> <![CDATA[Hello World]]>
Given this xml document: <projects><project><name>sample project</name><location>http://somewhere.com/</location></project></projects> And this linq to xml statement for retrieving
Consider this simple XML document. The serialized XML shown here is the result of
$q = $_GET['q']; // Load and parse the XML document $rss = simplexml_load_file('http://search.twitter.com/search.atom?lang=en&q=$q&rpp=100&page=1'); This
This question's solution makes hard-coded transformation of a sample XML tree into a flat
using LINQ to XML, this is a sample of my XML <shows> <Show Code=456
I have this code, loading XML documents on mouseenter, which works in Firefox: $(document).ready(function()
I have this sample string : &Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office
I developed a sample application to create an XML document, and I created and
I am trying to use jQuery to parse an in-memory XML document. This works

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.