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

  • Home
  • SEARCH
  • 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 6705719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:26:11+00:00 2026-05-26T07:26:11+00:00

Both programs are reading the same XML file. First program copies all data between

  • 0

Both programs are reading the same XML file. First program copies all data between <text></text> tags. And second program copies limited data from <text></text> tags.

I want to only limited data. So is it possible to use this statement in first program:

m = re.search(r'(?ms).*?{{(Infobox film.*?)}}', t.text)

First Program

from lxml import etree
doc = etree.parse('file.xml')
def first(seq,default=None):
  for item in seq:
    return item
  return default
    NSMAP=dict(mw="http://www.mediawiki.org/xml/export-0.5/")
for i,page in enumerate(doc.xpath('/mw:mediawiki/mw:page',namespaces=NSMAP)):
  text = first(page.xpath('./mw:revision/mw:text/text()',namespaces=NSMAP))
  id = first(page.xpath('./mw:id/text()',namespaces=NSMAP))
  title = first(page.xpath('./mw:title/text()',namespaces=NSMAP))
  print " %s"  % (text)

Second Program

import re
from xml.etree import ElementTree
with open('file.xml') as f:
    xml = ElementTree.parse(f)
    for t in xml.findall('//{http://www.mediawiki.org/xml/export-0.5/}text'):
    print '===================='
    m = re.search(r'(?ms).*?{{(Infobox film.*?)}}', t.text)
    if m:
        print m.group(1)

UPDATE: please help me. Is there any other alternative?

  • 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-26T07:26:12+00:00Added an answer on May 26, 2026 at 7:26 am

    I don’t see any reason why you wouldn’t be able to do the following at the end of your first program:

    m = re.search(r'(?ms).*?{{(Infobox film.*?)}}', text)
    if m:
        print m.group(1)
    

    As per what you describe, your text variable should contain all the text, and your regexp should then be able to filter out the necessary parts from that.

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

Sidebar

Related Questions

I made a program that both gathers data from a .txt file by reading
It is my first time to create a program with file reading and writing
tell me the examples of both the iPhone development programs. 1)Standard Program and 2)Enterprise
I'm reading in a text file using BinaryReader, then doing what I want with
I'm having trouble reading a compressed (deflated) data file using C# .NET DeflateStream(..., CompressionMode.Decompress)
I have 2 programs, both written in Java. The first launches several instances of
In this program, I am reading key.pc.db file and printing its mid value. #include
Why do we need both using namespace and include directives in C++ programs? For
I have two begininer programs, both using the 'while' function, one works correctly, and
What language should I use to develop programs for Nokia/Samsung/LG/Sony Ericsson phones? (Both Symbian

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.